1
1
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2
2
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
4
+ // RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
3
5
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
4
6
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
5
7
@@ -27,6 +29,24 @@ int shouldNotGenBranchRet(int x) {
27
29
// CIR: cir.store [[MINUS]], [[RETVAL]] : !s32i, !cir.ptr<!s32i>
28
30
// CIR: cir.br ^bb1
29
31
32
+ // LLVM: define dso_local i32 @_Z21shouldNotGenBranchReti
33
+ // LLVM: [[COND:%.*]] = load i32, ptr {{.*}}, align 4
34
+ // LLVM: [[CMP:%.*]] = icmp sgt i32 [[COND]], 5
35
+ // LLVM: br i1 [[CMP]], label %[[IFTHEN:.*]], label %[[IFEND:.*]]
36
+ // LLVM: [[IFTHEN]]:
37
+ // LLVM: br label %[[ERR:.*]]
38
+ // LLVM: [[IFEND]]:
39
+ // LLVM: br label %[[BB9:.*]]
40
+ // LLVM: [[BB9]]:
41
+ // LLVM: store i32 0, ptr %[[RETVAL:.*]], align 4
42
+ // LLVM: br label %[[BBRET:.*]]
43
+ // LLVM: [[BBRET]]:
44
+ // LLVM: [[RET:%.*]] = load i32, ptr %[[RETVAL]], align 4
45
+ // LLVM: ret i32 [[RET]]
46
+ // LLVM: [[ERR]]:
47
+ // LLVM: store i32 -1, ptr %[[RETVAL]], align 4
48
+ // LLVM: br label %10
49
+
30
50
// OGCG: define dso_local noundef i32 @_Z21shouldNotGenBranchReti
31
51
// OGCG: if.then:
32
52
// OGCG: br label %err
@@ -51,6 +71,17 @@ int shouldGenBranch(int x) {
51
71
// CIR: ^bb1:
52
72
// CIR: cir.label "err"
53
73
74
+ // LLVM: define dso_local i32 @_Z15shouldGenBranchi
75
+ // LLVM: br i1 [[CMP:%.*]], label %[[IFTHEN:.*]], label %[[IFEND:.*]]
76
+ // LLVM: [[IFTHEN]]:
77
+ // LLVM: br label %[[ERR:.*]]
78
+ // LLVM: [[IFEND]]:
79
+ // LLVM: br label %[[BB9:.*]]
80
+ // LLVM: [[BB9]]:
81
+ // LLVM: br label %[[ERR]]
82
+ // LLVM: [[ERR]]:
83
+ // LLVM: ret i32 [[RET:%.*]]
84
+
54
85
// OGCG: define dso_local noundef i32 @_Z15shouldGenBranchi
55
86
// OGCG: if.then:
56
87
// OGCG: br label %err
@@ -78,6 +109,15 @@ void severalLabelsInARow(int a) {
78
109
// CIR: ^bb[[#BLK3]]:
79
110
// CIR: cir.label "end2"
80
111
112
+ // LLVM: define dso_local void @_Z19severalLabelsInARowi
113
+ // LLVM: br label %[[END1:.*]]
114
+ // LLVM: [[UNRE:.*]]: ; No predecessors!
115
+ // LLVM: br label %[[END2:.*]]
116
+ // LLVM: [[END1]]:
117
+ // LLVM: br label %[[END2]]
118
+ // LLVM: [[END2]]:
119
+ // LLVM: ret
120
+
81
121
// OGCG: define dso_local void @_Z19severalLabelsInARowi
82
122
// OGCG: br label %end1
83
123
// OGCG: end1:
@@ -99,6 +139,13 @@ void severalGotosInARow(int a) {
99
139
// CIR: ^bb[[#BLK2:]]:
100
140
// CIR: cir.label "end"
101
141
142
+ // LLVM: define dso_local void @_Z18severalGotosInARowi
143
+ // LLVM: br label %[[END:.*]]
144
+ // LLVM: [[UNRE:.*]]: ; No predecessors!
145
+ // LLVM: br label %[[END]]
146
+ // LLVM: [[END]]:
147
+ // LLVM: ret void
148
+
102
149
// OGCG: define dso_local void @_Z18severalGotosInARowi(i32 noundef %a) #0 {
103
150
// OGCG: br label %end
104
151
// OGCG: end:
@@ -126,6 +173,14 @@ extern "C" void multiple_non_case(int v) {
126
173
// CIR: cir.call @action2()
127
174
// CIR: cir.break
128
175
176
+ // LLVM: define dso_local void @multiple_non_case
177
+ // LLVM: [[SWDEFAULT:.*]]:
178
+ // LLVM: call void @action1()
179
+ // LLVM: br label %[[L2:.*]]
180
+ // LLVM: [[L2]]:
181
+ // LLVM: call void @action2()
182
+ // LLVM: br label %[[BREAK:.*]]
183
+
129
184
// OGCG: define dso_local void @multiple_non_case
130
185
// OGCG: sw.default:
131
186
// OGCG: call void @action1()
@@ -158,6 +213,26 @@ extern "C" void case_follow_label(int v) {
158
213
// CIR: cir.call @action2()
159
214
// CIR: cir.goto "label"
160
215
216
+ // LLVM: define dso_local void @case_follow_label
217
+ // LLVM: switch i32 {{.*}}, label %[[SWDEFAULT:.*]] [
218
+ // LLVM: i32 1, label %[[LABEL:.*]]
219
+ // LLVM: i32 2, label %[[CASE2:.*]]
220
+ // LLVM: ]
221
+ // LLVM: [[LABEL]]:
222
+ // LLVM: br label %[[CASE2]]
223
+ // LLVM: [[CASE2]]:
224
+ // LLVM: call void @action1()
225
+ // LLVM: br label %[[BREAK:.*]]
226
+ // LLVM: [[BREAK]]:
227
+ // LLVM: br label %[[END:.*]]
228
+ // LLVM: [[SWDEFAULT]]:
229
+ // LLVM: call void @action2()
230
+ // LLVM: br label %[[LABEL]]
231
+ // LLVM: [[END]]:
232
+ // LLVM: br label %[[RET:.*]]
233
+ // LLVM: [[RET]]:
234
+ // LLVM: ret void
235
+
161
236
// OGCG: define dso_local void @case_follow_label
162
237
// OGCG: sw.bb:
163
238
// OGCG: br label %label
@@ -197,6 +272,26 @@ extern "C" void default_follow_label(int v) {
197
272
// CIR: cir.call @action2()
198
273
// CIR: cir.goto "label"
199
274
275
+ // LLVM: define dso_local void @default_follow_label
276
+ // LLVM: [[CASE1:.*]]:
277
+ // LLVM: br label %[[BB8:.*]]
278
+ // LLVM: [[BB8]]:
279
+ // LLVM: br label %[[CASE2:.*]]
280
+ // LLVM: [[CASE2]]:
281
+ // LLVM: call void @action1()
282
+ // LLVM: br label %[[BREAK:.*]]
283
+ // LLVM: [[LABEL:.*]]:
284
+ // LLVM: br label %[[SWDEFAULT:.*]]
285
+ // LLVM: [[SWDEFAULT]]:
286
+ // LLVM: call void @action2()
287
+ // LLVM: br label %[[BB9:.*]]
288
+ // LLVM: [[BB9]]:
289
+ // LLVM: br label %[[LABEL]]
290
+ // LLVM: [[BREAK]]:
291
+ // LLVM: br label %[[RET:.*]]
292
+ // LLVM: [[RET]]:
293
+ // LLVM: ret void
294
+
200
295
// OGCG: define dso_local void @default_follow_label
201
296
// OGCG: sw.bb:
202
297
// OGCG: call void @action1()
0 commit comments