1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; FIXME(ndesaulniers): get this test to pass with -verify-machineinstrs
3 ; enabled. https://github.com/llvm/llvm-project/issues/60827
4 ; RUN: llc -mtriple=x86_64-linux-gnu %s -o - -stop-after=finalize-isel \
5 ; RUN: -verify-machineinstrs=0 -start-before=x86-isel | FileCheck %s
7 ; One virtual register, w/o phi
9 ; CHECK-LABEL: name: test0
10 ; CHECK: bb.0 (%ir-block.0):
11 ; CHECK-NEXT: successors: %bb.1(0x80000000), %bb.2(0x00000000)
13 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 2686986 /* regdef:GR32_NOREX2 */, def %1, 13 /* imm */, %bb.2
14 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY %1
15 ; CHECK-NEXT: JMP_1 %bb.1
17 ; CHECK-NEXT: bb.1.cleanup:
18 ; CHECK-NEXT: [[MOV32ri:%[0-9]+]]:gr32 = MOV32ri 42
19 ; CHECK-NEXT: $eax = COPY [[MOV32ri]]
20 ; CHECK-NEXT: RET 0, $eax
22 ; CHECK-NEXT: bb.2.z.split (machine-block-address-taken, inlineasm-br-indirect-target):
23 ; CHECK-NEXT: $eax = COPY %1
24 ; CHECK-NEXT: RET 0, $eax
25 %direct = callbr i32 asm "", "=r,!i"()
26 to label %cleanup [label %z.split]
31 %indirect = call i32 @llvm.callbr.landingpad.i32(i32 %direct)
35 ; One virtual register, w/ phi
37 ; CHECK-LABEL: name: test1
39 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.1(0x00000000)
41 ; CHECK-NEXT: [[MOV32ri:%[0-9]+]]:gr32 = MOV32ri 42
42 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 2686986 /* regdef:GR32_NOREX2 */, def %4, 13 /* imm */, %bb.1
43 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY %4
44 ; CHECK-NEXT: JMP_1 %bb.2
46 ; CHECK-NEXT: bb.1.z.split (machine-block-address-taken, inlineasm-br-indirect-target):
47 ; CHECK-NEXT: successors: %bb.2(0x80000000)
49 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY %4
51 ; CHECK-NEXT: bb.2.cleanup:
52 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr32 = PHI [[MOV32ri]], %bb.0, [[COPY1]], %bb.1
53 ; CHECK-NEXT: $eax = COPY [[PHI]]
54 ; CHECK-NEXT: RET 0, $eax
56 %direct = callbr i32 asm "", "=r,!i"()
57 to label %cleanup [label %z.split]
60 %indirect = call i32 @llvm.callbr.landingpad.i32(i32 %direct)
64 %retval.0 = phi i32 [ %indirect, %z.split ], [ 42, %entry ]
68 ; Two virtual registers
70 ; CHECK-LABEL: name: test2
72 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.1(0x00000000)
74 ; CHECK-NEXT: [[MOV32ri:%[0-9]+]]:gr32 = MOV32ri 42
75 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 2686986 /* regdef:GR32_NOREX2 */, def %5, 2686986 /* regdef:GR32_NOREX2 */, def %6, 13 /* imm */, %bb.1
76 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY %6
77 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY %5
78 ; CHECK-NEXT: JMP_1 %bb.2
80 ; CHECK-NEXT: bb.1.z.split (machine-block-address-taken, inlineasm-br-indirect-target):
81 ; CHECK-NEXT: successors: %bb.2(0x80000000)
83 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr32 = COPY %5
85 ; CHECK-NEXT: bb.2.cleanup:
86 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr32 = PHI [[MOV32ri]], %bb.0, [[COPY2]], %bb.1
87 ; CHECK-NEXT: $eax = COPY [[PHI]]
88 ; CHECK-NEXT: RET 0, $eax
90 %direct = callbr { i32, i32 } asm "", "=r,=r,!i"()
91 to label %cleanup [label %z.split]
94 %indirect = call { i32, i32 } @llvm.callbr.landingpad.sl_i32i32s({ i32, i32 } %direct)
95 %asmresult2 = extractvalue { i32, i32 } %indirect, 0
99 %retval.0 = phi i32 [ %asmresult2, %z.split ], [ 42, %entry ]
103 ; One physical register
104 define i32 @test3() {
105 ; CHECK-LABEL: name: test3
107 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.1(0x00000000)
109 ; CHECK-NEXT: [[MOV32ri:%[0-9]+]]:gr32 = MOV32ri 42
110 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $ebx, 13 /* imm */, %bb.1
111 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $ebx
112 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY [[COPY]]
113 ; CHECK-NEXT: JMP_1 %bb.2
115 ; CHECK-NEXT: bb.1.z.split (machine-block-address-taken, inlineasm-br-indirect-target):
116 ; CHECK-NEXT: successors: %bb.2(0x80000000)
117 ; CHECK-NEXT: liveins: $ebx
119 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr32 = COPY $ebx
120 ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gr32 = COPY [[COPY2]]
122 ; CHECK-NEXT: bb.2.cleanup:
123 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr32 = PHI [[MOV32ri]], %bb.0, [[COPY3]], %bb.1
124 ; CHECK-NEXT: $eax = COPY [[PHI]]
125 ; CHECK-NEXT: RET 0, $eax
127 %direct = callbr i32 asm "", "={bx},!i"()
128 to label %cleanup [label %z.split]
131 %indirect = call i32 @llvm.callbr.landingpad.i32(i32 %direct)
135 %retval.0 = phi i32 [ %indirect, %z.split ], [ 42, %entry ]
139 ; Two physical registers
140 define i32 @test4() {
141 ; CHECK-LABEL: name: test4
143 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.1(0x00000000)
145 ; CHECK-NEXT: [[MOV32ri:%[0-9]+]]:gr32 = MOV32ri 42
146 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $ebx, 10 /* regdef */, implicit-def $edx, 13 /* imm */, %bb.1
147 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $ebx
148 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edx
149 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr32 = COPY [[COPY1]]
150 ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gr32 = COPY [[COPY]]
151 ; CHECK-NEXT: JMP_1 %bb.2
153 ; CHECK-NEXT: bb.1.z.split (machine-block-address-taken, inlineasm-br-indirect-target):
154 ; CHECK-NEXT: successors: %bb.2(0x80000000)
155 ; CHECK-NEXT: liveins: $ebx, $edx
157 ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gr32 = COPY $ebx
158 ; CHECK-NEXT: [[COPY5:%[0-9]+]]:gr32 = COPY [[COPY4]]
160 ; CHECK-NEXT: bb.2.cleanup:
161 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr32 = PHI [[MOV32ri]], %bb.0, [[COPY5]], %bb.1
162 ; CHECK-NEXT: $eax = COPY [[PHI]]
163 ; CHECK-NEXT: RET 0, $eax
165 %direct = callbr { i32, i32 } asm "", "={bx},={dx},!i"()
166 to label %cleanup [label %z.split]
169 %indirect = call { i32, i32 } @llvm.callbr.landingpad.sl_i32i32s({ i32, i32 } %direct)
170 %asmresult2 = extractvalue { i32, i32 } %indirect, 0
174 %retval.0 = phi i32 [ %asmresult2, %z.split ], [ 42, %entry ]
178 ; Test the same destination appearing in the direct/fallthrough branch as the
179 ; indirect branch. Physreg.
180 define i32 @test5() {
181 ; CHECK-LABEL: name: test5
183 ; CHECK-NEXT: successors: %bb.1(0x80000000)
185 ; CHECK-NEXT: INLINEASM_BR &"# $0", 0 /* attdialect */, 10 /* regdef */, implicit-def $ebx, 13 /* imm */, %bb.1
186 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $ebx
187 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY [[COPY]]
188 ; CHECK-NEXT: JMP_1 %bb.1
190 ; CHECK-NEXT: bb.1.cleanup (machine-block-address-taken, inlineasm-br-indirect-target):
191 ; CHECK-NEXT: liveins: $ebx
193 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr32 = COPY $ebx
194 ; CHECK-NEXT: $eax = COPY [[COPY2]]
195 ; CHECK-NEXT: RET 0, $eax
197 %direct = callbr i32 asm "# $0", "={bx},!i"()
198 to label %cleanup [label %cleanup]
201 %indirect = call i32 @llvm.callbr.landingpad.i32(i32 %direct)
205 ; "The Devil's cross" (i.e. two asm goto with conflicting physreg constraints
206 ; going to the same destination) as expressed by clang.
207 define i64 @test6() {
208 ; CHECK-LABEL: name: test6
210 ; CHECK-NEXT: successors: %bb.1(0x80000000), %bb.3(0x00000000)
212 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $rdx, 13 /* imm */, %bb.3
213 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY $rdx
214 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY [[COPY]]
215 ; CHECK-NEXT: JMP_1 %bb.1
217 ; CHECK-NEXT: bb.1.asm.fallthrough:
218 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.4(0x00000000)
220 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $rbx, 13 /* imm */, %bb.4
221 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr64 = COPY $rbx
222 ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gr64 = COPY [[COPY2]]
223 ; CHECK-NEXT: JMP_1 %bb.2
225 ; CHECK-NEXT: bb.2.foo:
226 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr64 = PHI %3, %bb.3, [[COPY3]], %bb.1, %4, %bb.4
227 ; CHECK-NEXT: $rax = COPY [[PHI]]
228 ; CHECK-NEXT: RET 0, $rax
230 ; CHECK-NEXT: bb.3.foo.split (machine-block-address-taken, inlineasm-br-indirect-target):
231 ; CHECK-NEXT: successors: %bb.2(0x80000000)
232 ; CHECK-NEXT: liveins: $rdx
234 ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gr64 = COPY $rdx
235 ; CHECK-NEXT: [[COPY5:%[0-9]+]]:gr64 = COPY [[COPY4]]
236 ; CHECK-NEXT: JMP_1 %bb.2
238 ; CHECK-NEXT: bb.4.foo.split2 (machine-block-address-taken, inlineasm-br-indirect-target):
239 ; CHECK-NEXT: successors: %bb.2(0x80000000)
240 ; CHECK-NEXT: liveins: $rbx
242 ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gr64 = COPY $rbx
243 ; CHECK-NEXT: [[COPY7:%[0-9]+]]:gr64 = COPY [[COPY6]]
244 ; CHECK-NEXT: JMP_1 %bb.2
246 %0 = callbr i64 asm "", "={dx},!i"()
247 to label %asm.fallthrough [label %foo.split]
250 %1 = callbr i64 asm "", "={bx},!i"()
251 to label %foo [label %foo.split2]
254 %x.0 = phi i64 [ %3, %foo.split2 ], [ %2, %foo.split ], [ %1, %asm.fallthrough ]
258 %2 = call i64 @llvm.callbr.landingpad.i64(i64 %0)
262 %3 = call i64 @llvm.callbr.landingpad.i64(i64 %1)
267 ; Test a callbr looping back on itself.
268 define i32 @test7() {
269 ; CHECK-LABEL: name: test7
271 ; CHECK-NEXT: successors: %bb.1(0x80000000)
273 ; CHECK-NEXT: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
275 ; CHECK-NEXT: bb.1.retry:
276 ; CHECK-NEXT: successors: %bb.2(0x80000000), %bb.3(0x00000000)
278 ; CHECK-NEXT: [[PHI:%[0-9]+]]:gr32 = PHI [[DEF]], %bb.0, %2, %bb.3
279 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY [[PHI]]
280 ; CHECK-NEXT: INLINEASM_BR &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $edx, 2147483657 /* reguse tiedto:$0 */, [[COPY]](tied-def 3), 13 /* imm */, %bb.3
281 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edx
282 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr32 = COPY [[COPY1]]
283 ; CHECK-NEXT: JMP_1 %bb.2
285 ; CHECK-NEXT: bb.2.asm.fallthrough:
286 ; CHECK-NEXT: $eax = COPY [[COPY2]]
287 ; CHECK-NEXT: RET 0, $eax
289 ; CHECK-NEXT: bb.3.retry.split (machine-block-address-taken, inlineasm-br-indirect-target):
290 ; CHECK-NEXT: successors: %bb.1(0x80000000)
291 ; CHECK-NEXT: liveins: $edx
293 ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gr32 = COPY $edx
294 ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gr32 = COPY [[COPY3]]
295 ; CHECK-NEXT: JMP_1 %bb.1
300 %x.0 = phi i32 [ undef, %entry ], [ %1, %retry.split ]
301 %0 = callbr i32 asm "", "={dx},0,!i"(i32 %x.0)
302 to label %asm.fallthrough [label %retry.split]
308 %1 = call i32 @llvm.callbr.landingpad.i32(i32 %0)
312 ; Test the same destination appearing in the direct/fallthrough branch as the
313 ; indirect branch. Same as test5 but with a virtreg rather than a physreg
315 define i32 @test8() {
316 ; CHECK-LABEL: name: test8
318 ; CHECK-NEXT: successors: %bb.1(0x80000000)
320 ; CHECK-NEXT: INLINEASM_BR &"# $0", 0 /* attdialect */, 2686986 /* regdef:GR32_NOREX2 */, def %1, 13 /* imm */, %bb.1
321 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY %1
322 ; CHECK-NEXT: JMP_1 %bb.1
324 ; CHECK-NEXT: bb.1.cleanup (machine-block-address-taken, inlineasm-br-indirect-target):
325 ; CHECK-NEXT: $eax = COPY %1
326 ; CHECK-NEXT: RET 0, $eax
328 %direct = callbr i32 asm "# $0", "=r,!i"()
329 to label %cleanup [label %cleanup]
332 %indirect = call i32 @llvm.callbr.landingpad.i32(i32 %direct)
336 define i64 @condition_code() {
337 ; CHECK-LABEL: name: condition_code
338 ; CHECK: bb.0 (%ir-block.0):
339 ; CHECK-NEXT: successors: %bb.1(0x80000000), %bb.2(0x00000000)
341 ; CHECK-NEXT: INLINEASM_BR &"", 16 /* maystore attdialect */, 2359306 /* regdef:GR32 */, def %1, 13 /* imm */, %bb.2
342 ; CHECK-NEXT: [[SETCCr:%[0-9]+]]:gr8 = SETCCr 4, implicit $eflags
343 ; CHECK-NEXT: [[MOVZX32rr8_:%[0-9]+]]:gr32 = MOVZX32rr8 killed [[SETCCr]]
344 ; CHECK-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gr64 = SUBREG_TO_REG 0, killed [[MOVZX32rr8_]], %subreg.sub_32bit
345 ; CHECK-NEXT: JMP_1 %bb.1
347 ; CHECK-NEXT: bb.1.b:
348 ; CHECK-NEXT: $rax = COPY [[SUBREG_TO_REG]]
349 ; CHECK-NEXT: RET 0, $rax
351 ; CHECK-NEXT: bb.2.c (machine-block-address-taken, inlineasm-br-indirect-target):
352 ; CHECK-NEXT: [[SETCCr1:%[0-9]+]]:gr8 = SETCCr 4, implicit $eflags
353 ; CHECK-NEXT: [[MOVZX32rr8_1:%[0-9]+]]:gr32 = MOVZX32rr8 killed [[SETCCr1]]
354 ; CHECK-NEXT: [[SUBREG_TO_REG1:%[0-9]+]]:gr64 = SUBREG_TO_REG 0, killed [[MOVZX32rr8_1]], %subreg.sub_32bit
355 ; CHECK-NEXT: $rax = COPY [[SUBREG_TO_REG1]]
356 ; CHECK-NEXT: RET 0, $rax
357 %a = callbr i64 asm "", "={@ccz},!i"()
358 to label %b [label %c]
364 %1 = call i64 @llvm.callbr.landingpad.i64(i64 %a)
368 declare i64 @llvm.callbr.landingpad.i64(i64)
369 declare i32 @llvm.callbr.landingpad.i32(i32)
370 declare { i32, i32 } @llvm.callbr.landingpad.sl_i32i32s({ i32, i32 })