1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -O2 -mtriple=i386-unknown-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s
3 @.str = external dso_local unnamed_addr constant [6 x i8], align 1
4 @a = external dso_local local_unnamed_addr global i32, align 4
5 @h = external dso_local local_unnamed_addr global i32, align 4
6 @g = external dso_local local_unnamed_addr global i8, align 1
8 define dso_local void @fn() {
10 ; CHECK: # %bb.0: # %entry
11 ; CHECK-NEXT: pushl %ebp
12 ; CHECK-NEXT: .cfi_def_cfa_offset 8
13 ; CHECK-NEXT: pushl %ebx
14 ; CHECK-NEXT: .cfi_def_cfa_offset 12
15 ; CHECK-NEXT: pushl %edi
16 ; CHECK-NEXT: .cfi_def_cfa_offset 16
17 ; CHECK-NEXT: pushl %esi
18 ; CHECK-NEXT: .cfi_def_cfa_offset 20
19 ; CHECK-NEXT: subl $28, %esp
20 ; CHECK-NEXT: .cfi_def_cfa_offset 48
21 ; CHECK-NEXT: .cfi_offset %esi, -20
22 ; CHECK-NEXT: .cfi_offset %edi, -16
23 ; CHECK-NEXT: .cfi_offset %ebx, -12
24 ; CHECK-NEXT: .cfi_offset %ebp, -8
25 ; CHECK-NEXT: xorl %ebx, %ebx
26 ; CHECK-NEXT: # implicit-def: $ecx
27 ; CHECK-NEXT: # implicit-def: $edi
28 ; CHECK-NEXT: # implicit-def: $al
29 ; CHECK-NEXT: # kill: killed $al
30 ; CHECK-NEXT: # implicit-def: $al
31 ; CHECK-NEXT: # implicit-def: $ebp
32 ; CHECK-NEXT: jmp .LBB0_1
33 ; CHECK-NEXT: .p2align 4, 0x90
34 ; CHECK-NEXT: .LBB0_16: # in Loop: Header=BB0_1 Depth=1
35 ; CHECK-NEXT: movb %al, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
36 ; CHECK-NEXT: movb %dh, %al
37 ; CHECK-NEXT: .LBB0_1: # %for.cond
38 ; CHECK-NEXT: # =>This Loop Header: Depth=1
39 ; CHECK-NEXT: # Child Loop BB0_22 Depth 2
40 ; CHECK-NEXT: movb %al, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
41 ; CHECK-NEXT: cmpb $8, %al
42 ; CHECK-NEXT: ja .LBB0_3
43 ; CHECK-NEXT: # %bb.2: # %for.cond
44 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
45 ; CHECK-NEXT: testb %bl, %bl
46 ; CHECK-NEXT: je .LBB0_3
47 ; CHECK-NEXT: # %bb.4: # %if.end
48 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
49 ; CHECK-NEXT: movl %ecx, %eax
52 ; CHECK-NEXT: movl %eax, %esi
53 ; CHECK-NEXT: movb %cl, %dh
54 ; CHECK-NEXT: movl $0, h
55 ; CHECK-NEXT: movzbl {{[-0-9]+}}(%e{{[sb]}}p), %eax # 1-byte Folded Reload
56 ; CHECK-NEXT: cmpb $8, %al
57 ; CHECK-NEXT: jg .LBB0_8
58 ; CHECK-NEXT: # %bb.5: # %if.then13
59 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
60 ; CHECK-NEXT: movl $.str, (%esp)
61 ; CHECK-NEXT: movb %dh, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
62 ; CHECK-NEXT: calll printf
63 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dh # 1-byte Reload
64 ; CHECK-NEXT: testb %bl, %bl
65 ; CHECK-NEXT: movl %esi, %ecx
66 ; CHECK-NEXT: # implicit-def: $eax
67 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
68 ; CHECK-NEXT: movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
69 ; CHECK-NEXT: movb %dh, %dl
70 ; CHECK-NEXT: je .LBB0_6
71 ; CHECK-NEXT: jmp .LBB0_18
72 ; CHECK-NEXT: .p2align 4, 0x90
73 ; CHECK-NEXT: .LBB0_3: # %if.then
74 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
75 ; CHECK-NEXT: movl $.str, (%esp)
76 ; CHECK-NEXT: calll printf
77 ; CHECK-NEXT: # implicit-def: $eax
78 ; CHECK-NEXT: movzbl {{[-0-9]+}}(%e{{[sb]}}p), %edx # 1-byte Folded Reload
79 ; CHECK-NEXT: .LBB0_6: # %for.cond35
80 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
81 ; CHECK-NEXT: testl %edi, %edi
82 ; CHECK-NEXT: je .LBB0_7
83 ; CHECK-NEXT: .LBB0_11: # %af
84 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
85 ; CHECK-NEXT: testb %bl, %bl
86 ; CHECK-NEXT: jne .LBB0_12
87 ; CHECK-NEXT: .LBB0_19: # %if.end39
88 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
89 ; CHECK-NEXT: testl %eax, %eax
90 ; CHECK-NEXT: je .LBB0_21
91 ; CHECK-NEXT: # %bb.20: # %if.then41
92 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
93 ; CHECK-NEXT: movl $0, {{[0-9]+}}(%esp)
94 ; CHECK-NEXT: movl $fn, {{[0-9]+}}(%esp)
95 ; CHECK-NEXT: movl $.str, (%esp)
96 ; CHECK-NEXT: calll printf
97 ; CHECK-NEXT: .LBB0_21: # %for.end46
98 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
99 ; CHECK-NEXT: # implicit-def: $al
100 ; CHECK-NEXT: # implicit-def: $dh
101 ; CHECK-NEXT: # implicit-def: $ebp
102 ; CHECK-NEXT: jmp .LBB0_22
103 ; CHECK-NEXT: .p2align 4, 0x90
104 ; CHECK-NEXT: .LBB0_8: # %if.end21
105 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
106 ; CHECK-NEXT: # implicit-def: $ebp
107 ; CHECK-NEXT: jmp .LBB0_9
108 ; CHECK-NEXT: .p2align 4, 0x90
109 ; CHECK-NEXT: .LBB0_7: # in Loop: Header=BB0_1 Depth=1
110 ; CHECK-NEXT: xorl %edi, %edi
111 ; CHECK-NEXT: movb %dl, %dh
112 ; CHECK-NEXT: movzbl {{[-0-9]+}}(%e{{[sb]}}p), %eax # 1-byte Folded Reload
113 ; CHECK-NEXT: .p2align 4, 0x90
114 ; CHECK-NEXT: .LBB0_22: # %for.cond47
115 ; CHECK-NEXT: # Parent Loop BB0_1 Depth=1
116 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
117 ; CHECK-NEXT: testb %bl, %bl
118 ; CHECK-NEXT: jne .LBB0_22
119 ; CHECK-NEXT: # %bb.23: # %for.cond47
120 ; CHECK-NEXT: # in Loop: Header=BB0_22 Depth=2
121 ; CHECK-NEXT: testb %bl, %bl
122 ; CHECK-NEXT: jne .LBB0_22
123 ; CHECK-NEXT: .LBB0_9: # %ae
124 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
125 ; CHECK-NEXT: testb %bl, %bl
126 ; CHECK-NEXT: jne .LBB0_10
127 ; CHECK-NEXT: # %bb.13: # %if.end26
128 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
129 ; CHECK-NEXT: xorl %ecx, %ecx
130 ; CHECK-NEXT: testb %al, %al
131 ; CHECK-NEXT: je .LBB0_14
132 ; CHECK-NEXT: # %bb.15: # %if.end26
133 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
134 ; CHECK-NEXT: testl %ebp, %ebp
135 ; CHECK-NEXT: jne .LBB0_16
136 ; CHECK-NEXT: # %bb.17: # %if.then31
137 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
138 ; CHECK-NEXT: xorl %ecx, %ecx
139 ; CHECK-NEXT: movb %al, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
140 ; CHECK-NEXT: xorl %ebp, %ebp
141 ; CHECK-NEXT: .LBB0_18: # %for.inc
142 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
143 ; CHECK-NEXT: movb %dh, %al
144 ; CHECK-NEXT: jmp .LBB0_1
145 ; CHECK-NEXT: .p2align 4, 0x90
146 ; CHECK-NEXT: .LBB0_10: # in Loop: Header=BB0_1 Depth=1
147 ; CHECK-NEXT: # implicit-def: $eax
148 ; CHECK-NEXT: testb %bl, %bl
149 ; CHECK-NEXT: je .LBB0_19
150 ; CHECK-NEXT: .LBB0_12: # in Loop: Header=BB0_1 Depth=1
151 ; CHECK-NEXT: # implicit-def: $edi
152 ; CHECK-NEXT: # implicit-def: $cl
153 ; CHECK-NEXT: # kill: killed $cl
154 ; CHECK-NEXT: # implicit-def: $dl
155 ; CHECK-NEXT: # implicit-def: $ebp
156 ; CHECK-NEXT: testl %edi, %edi
157 ; CHECK-NEXT: jne .LBB0_11
158 ; CHECK-NEXT: jmp .LBB0_7
159 ; CHECK-NEXT: .p2align 4, 0x90
160 ; CHECK-NEXT: .LBB0_14: # in Loop: Header=BB0_1 Depth=1
161 ; CHECK-NEXT: movb %al, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
162 ; CHECK-NEXT: movb %dh, %al
163 ; CHECK-NEXT: jmp .LBB0_1
167 for.cond: ; preds = %for.inc, %entry
168 %l.0 = phi i16 [ undef, %entry ], [ 0, %for.inc ]
169 %m.0 = phi i32 [ undef, %entry ], [ %m.2, %for.inc ]
170 %i.0 = phi i32 [ undef, %entry ], [ %i.2, %for.inc ]
171 %p.0 = phi i8 [ undef, %entry ], [ %p.2, %for.inc ]
172 %k.0 = phi i8 [ undef, %entry ], [ %k.2, %for.inc ]
173 %q.0 = phi i32 [ undef, %entry ], [ %q.2, %for.inc ]
174 %cmp = icmp ugt i8 %k.0, 8
175 %or.cond61 = or i1 %cmp, undef
176 br i1 %or.cond61, label %if.then, label %if.end
178 if.then: ; preds = %for.cond
179 tail call void (ptr, ...) @printf(ptr @.str, i64 undef)
182 if.end: ; preds = %for.cond
183 %0 = load i32, ptr @a, align 4
184 %div = sdiv i32 %m.0, %0
187 ac: ; preds = %ac, %if.end
188 br i1 undef, label %if.end9, label %ac
190 if.end9: ; preds = %ac
191 %conv3 = trunc i32 %m.0 to i8
192 %conv5 = sext i16 %l.0 to i32
193 store i32 %conv5, ptr @h, align 4
194 %cmp11 = icmp slt i8 %k.0, 9
195 br i1 %cmp11, label %if.then13, label %if.end21
197 if.then13: ; preds = %if.end9
198 tail call void (ptr, ...) @printf(ptr @.str, i64 undef)
199 br i1 undef, label %for.inc, label %for.cond35
201 if.end21: ; preds = %if.end9
202 %1 = load i8, ptr @g, align 1
205 ae: ; preds = %for.cond47, %if.end21
206 %l.2 = phi i16 [ undef, %if.end21 ], [ 0, %for.cond47 ]
207 %i.1 = phi i32 [ %i.0, %if.end21 ], [ %i.5, %for.cond47 ]
208 %p.1 = phi i8 [ %k.0, %if.end21 ], [ %p.6, %for.cond47 ]
209 %k.1 = phi i8 [ %conv3, %if.end21 ], [ %k.6, %for.cond47 ]
210 %q.1 = phi i32 [ undef, %if.end21 ], [ %q.5, %for.cond47 ]
211 br i1 undef, label %if.end26, label %af
213 if.end26: ; preds = %ae
214 %tobool27 = icmp eq i32 %q.1, 0
215 %tobool30 = icmp ne i8 %p.1, 0
216 %or.cond = and i1 %tobool30, %tobool27
217 br i1 %or.cond, label %if.then31, label %for.inc
219 if.then31: ; preds = %if.end26
222 for.inc: ; preds = %if.then31, %if.end26, %if.then13
223 %m.2 = phi i32 [ 0, %if.then31 ], [ 0, %if.end26 ], [ %div, %if.then13 ]
224 %i.2 = phi i32 [ %i.1, %if.then31 ], [ %i.1, %if.end26 ], [ %i.0, %if.then13 ]
225 %p.2 = phi i8 [ %p.1, %if.then31 ], [ %p.1, %if.end26 ], [ undef, %if.then13 ]
226 %k.2 = phi i8 [ %k.1, %if.then31 ], [ %k.1, %if.end26 ], [ %conv3, %if.then13 ]
227 %q.2 = phi i32 [ 0, %if.then31 ], [ %q.1, %if.end26 ], [ %q.0, %if.then13 ]
228 %2 = load i32, ptr @h, align 4
231 for.cond35: ; preds = %for.inc44, %if.then13, %if.then
232 %i.3 = phi i32 [ undef, %for.inc44 ], [ %i.0, %if.then ], [ %i.0, %if.then13 ]
233 %o.2 = phi i32 [ %o.3, %for.inc44 ], [ undef, %if.then ], [ undef, %if.then13 ]
234 %p.4 = phi i8 [ undef, %for.inc44 ], [ %p.0, %if.then ], [ %k.0, %if.then13 ]
235 %k.4 = phi i8 [ undef, %for.inc44 ], [ %k.0, %if.then ], [ %conv3, %if.then13 ]
236 %q.3 = phi i32 [ undef, %for.inc44 ], [ %q.0, %if.then ], [ %q.0, %if.then13 ]
237 %tobool36 = icmp eq i32 %i.3, 0
238 br i1 %tobool36, label %for.end46, label %af
240 af: ; preds = %for.cond35, %ae
241 %i.4 = phi i32 [ %i.3, %for.cond35 ], [ %i.1, %ae ]
242 %o.3 = phi i32 [ %o.2, %for.cond35 ], [ undef, %ae ]
243 br i1 undef, label %if.end39, label %for.inc44
245 if.end39: ; preds = %af
246 %tobool40 = icmp eq i32 %o.3, 0
247 br i1 %tobool40, label %for.end46, label %if.then41
249 if.then41: ; preds = %if.end39
250 tail call void (ptr, ...) @printf(ptr @.str, i64 ptrtoint (ptr @fn to i64))
253 for.inc44: ; preds = %af
256 for.end46: ; preds = %if.then41, %if.end39, %for.cond35
257 %i.5 = phi i32 [ %i.4, %if.then41 ], [ %i.4, %if.end39 ], [ 0, %for.cond35 ]
258 %p.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %p.4, %for.cond35 ]
259 %k.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %k.4, %for.cond35 ]
260 %q.5 = phi i32 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %q.3, %for.cond35 ]
263 for.cond47: ; preds = %for.cond47, %for.end46
264 %brmerge = or i1 false, undef
265 br i1 %brmerge, label %for.cond47, label %ae
268 declare dso_local void @printf(ptr nocapture readonly, ...) local_unnamed_addr
271 ; Testcase used to fail -verify-coalescing, reduced IR test which
273 define void @verifier_error_reduced_issue38788(i1 %cmp11) {
274 ; CHECK-LABEL: verifier_error_reduced_issue38788:
275 ; CHECK: # %bb.0: # %entry
276 ; CHECK-NEXT: pushl %ebx
277 ; CHECK-NEXT: .cfi_def_cfa_offset 8
278 ; CHECK-NEXT: .cfi_offset %ebx, -8
279 ; CHECK-NEXT: movzbl {{[0-9]+}}(%esp), %eax
280 ; CHECK-NEXT: xorl %ecx, %ecx
281 ; CHECK-NEXT: xorl %ebx, %ebx
282 ; CHECK-NEXT: jmp .LBB1_1
283 ; CHECK-NEXT: .p2align 4, 0x90
284 ; CHECK-NEXT: .LBB1_7: # %if.end26
285 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
286 ; CHECK-NEXT: movl %ecx, %edx
287 ; CHECK-NEXT: .LBB1_8: # %for.inc
288 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
289 ; CHECK-NEXT: movl %eax, %ecx
290 ; CHECK-NEXT: movl %edx, %ebx
291 ; CHECK-NEXT: movzbl {{[0-9]+}}(%esp), %eax
292 ; CHECK-NEXT: .LBB1_1: # %for.cond
293 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
294 ; CHECK-NEXT: testb $1, %al
295 ; CHECK-NEXT: je .LBB1_3
296 ; CHECK-NEXT: # %bb.2: # in Loop: Header=BB1_1 Depth=1
297 ; CHECK-NEXT: xorl %eax, %eax
298 ; CHECK-NEXT: jmp .LBB1_5
299 ; CHECK-NEXT: .p2align 4, 0x90
300 ; CHECK-NEXT: .LBB1_3: # %if.end
301 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
302 ; CHECK-NEXT: testb $1, %al
303 ; CHECK-NEXT: je .LBB1_4
304 ; CHECK-NEXT: # %bb.9: # %if.then13
305 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
306 ; CHECK-NEXT: xorl %edx, %edx
307 ; CHECK-NEXT: testb $1, %al
308 ; CHECK-NEXT: movl %ebx, %eax
309 ; CHECK-NEXT: movl $0, %ebx
310 ; CHECK-NEXT: jne .LBB1_8
311 ; CHECK-NEXT: jmp .LBB1_5
312 ; CHECK-NEXT: .p2align 4, 0x90
313 ; CHECK-NEXT: .LBB1_4: # in Loop: Header=BB1_1 Depth=1
314 ; CHECK-NEXT: movl %ebx, %eax
315 ; CHECK-NEXT: xorl %ebx, %ebx
316 ; CHECK-NEXT: .LBB1_5: # %if.end26
317 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
318 ; CHECK-NEXT: testb %cl, %cl
319 ; CHECK-NEXT: je .LBB1_7
320 ; CHECK-NEXT: # %bb.6: # %if.end26
321 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
322 ; CHECK-NEXT: movl %ebx, %ecx
323 ; CHECK-NEXT: jmp .LBB1_7
327 for.cond: ; preds = %for.inc, %entry
328 %p.0 = phi i8 [ 0, %entry ], [ %p.2, %for.inc ]
329 %k.0 = phi i8 [ 0, %entry ], [ %k.2, %for.inc ]
330 br i1 %cmp11, label %for.cond35, label %if.end
332 if.end: ; preds = %for.cond
333 br i1 %cmp11, label %if.then13, label %if.end26
335 if.then13: ; preds = %if.end
336 br i1 %cmp11, label %for.inc, label %for.cond35
338 if.end26: ; preds = %for.cond35, %if.end
339 %p.1 = phi i8 [ %p.4, %for.cond35 ], [ %k.0, %if.end ]
340 %k.1 = phi i8 [ %k.4, %for.cond35 ], [ 0, %if.end ]
341 %tobool30 = icmp ne i8 %p.0, 0
342 %spec.select1 = select i1 %tobool30, i8 %k.1, i8 0
345 for.inc: ; preds = %if.end26, %if.then13
346 %p.2 = phi i8 [ poison, %if.then13 ], [ %p.1, %if.end26 ]
347 %k.2 = phi i8 [ 0, %if.then13 ], [ %spec.select1, %if.end26 ]
348 %0 = load i32, ptr null, align 4
351 for.cond35: ; preds = %if.then13, %for.cond
352 %p.4 = phi i8 [ %k.0, %if.then13 ], [ 0, %for.cond ]
353 %k.4 = phi i8 [ 0, %if.then13 ], [ %k.0, %for.cond ]
354 %tobool36 = icmp eq i32 0, 0