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: $dh
29 ; CHECK-NEXT: # implicit-def: $al
30 ; CHECK-NEXT: # kill: killed $al
31 ; CHECK-NEXT: # implicit-def: $ebp
32 ; CHECK-NEXT: jmp .LBB0_1
33 ; CHECK-NEXT: .p2align 4
34 ; CHECK-NEXT: .LBB0_15: # %for.inc
35 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
36 ; CHECK-NEXT: movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
37 ; CHECK-NEXT: .LBB0_1: # %for.cond
38 ; CHECK-NEXT: # =>This Loop Header: Depth=1
39 ; CHECK-NEXT: # Child Loop BB0_19 Depth 2
40 ; CHECK-NEXT: testb %bl, %bl
41 ; CHECK-NEXT: jne .LBB0_3
42 ; CHECK-NEXT: # %bb.2: # %if.then
43 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
44 ; CHECK-NEXT: movb %dh, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
45 ; CHECK-NEXT: movl $.str, (%esp)
46 ; CHECK-NEXT: calll printf
47 ; CHECK-NEXT: # implicit-def: $eax
48 ; CHECK-NEXT: movzbl {{[-0-9]+}}(%e{{[sb]}}p), %edx # 1-byte Folded Reload
49 ; CHECK-NEXT: testl %edi, %edi
50 ; CHECK-NEXT: jne .LBB0_10
51 ; CHECK-NEXT: jmp .LBB0_6
52 ; CHECK-NEXT: .p2align 4
53 ; CHECK-NEXT: .LBB0_3: # %if.end
54 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
55 ; CHECK-NEXT: movl %ecx, %eax
58 ; CHECK-NEXT: movl %ecx, %edx
59 ; CHECK-NEXT: movl $0, h
60 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dh # 1-byte Reload
61 ; CHECK-NEXT: cmpb $8, %dh
62 ; CHECK-NEXT: jg .LBB0_7
63 ; CHECK-NEXT: # %bb.4: # %if.then13
64 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
65 ; CHECK-NEXT: movl %eax, %esi
66 ; CHECK-NEXT: movl $.str, (%esp)
67 ; CHECK-NEXT: movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
68 ; CHECK-NEXT: calll printf
69 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dh # 1-byte Reload
70 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
71 ; CHECK-NEXT: testb %bl, %bl
72 ; CHECK-NEXT: movl %esi, %ecx
73 ; CHECK-NEXT: # implicit-def: $eax
74 ; CHECK-NEXT: movb %dh, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
75 ; CHECK-NEXT: jne .LBB0_15
76 ; CHECK-NEXT: .p2align 4
77 ; CHECK-NEXT: # %bb.5: # %for.cond35
78 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
79 ; CHECK-NEXT: testl %edi, %edi
80 ; CHECK-NEXT: je .LBB0_6
81 ; CHECK-NEXT: .LBB0_10: # %af
82 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
83 ; CHECK-NEXT: testb %bl, %bl
84 ; CHECK-NEXT: jne .LBB0_11
85 ; CHECK-NEXT: .LBB0_16: # %if.end39
86 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
87 ; CHECK-NEXT: testl %eax, %eax
88 ; CHECK-NEXT: je .LBB0_18
89 ; CHECK-NEXT: # %bb.17: # %if.then41
90 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
91 ; CHECK-NEXT: movl $0, {{[0-9]+}}(%esp)
92 ; CHECK-NEXT: movl $fn, {{[0-9]+}}(%esp)
93 ; CHECK-NEXT: movl $.str, (%esp)
94 ; CHECK-NEXT: calll printf
95 ; CHECK-NEXT: .LBB0_18: # %for.end46
96 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
97 ; CHECK-NEXT: # implicit-def: $dh
98 ; CHECK-NEXT: # implicit-def: $dl
99 ; CHECK-NEXT: # implicit-def: $ebp
100 ; CHECK-NEXT: jmp .LBB0_19
101 ; CHECK-NEXT: .p2align 4
102 ; CHECK-NEXT: .LBB0_7: # %if.end21
103 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
104 ; CHECK-NEXT: # implicit-def: $ebp
105 ; CHECK-NEXT: jmp .LBB0_8
106 ; CHECK-NEXT: .p2align 4
107 ; CHECK-NEXT: .LBB0_6: # in Loop: Header=BB0_1 Depth=1
108 ; CHECK-NEXT: xorl %edi, %edi
109 ; CHECK-NEXT: movb {{[-0-9]+}}(%e{{[sb]}}p), %dh # 1-byte Reload
110 ; CHECK-NEXT: .p2align 4
111 ; CHECK-NEXT: .LBB0_19: # %for.cond47
112 ; CHECK-NEXT: # Parent Loop BB0_1 Depth=1
113 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
114 ; CHECK-NEXT: testb %bl, %bl
115 ; CHECK-NEXT: jne .LBB0_19
116 ; CHECK-NEXT: .LBB0_8: # %ae
117 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
118 ; CHECK-NEXT: testb %bl, %bl
119 ; CHECK-NEXT: jne .LBB0_9
120 ; CHECK-NEXT: # %bb.12: # %if.end26
121 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
122 ; CHECK-NEXT: xorl %ecx, %ecx
123 ; CHECK-NEXT: testb %dh, %dh
124 ; CHECK-NEXT: je .LBB0_15
125 ; CHECK-NEXT: # %bb.13: # %if.end26
126 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
127 ; CHECK-NEXT: testl %ebp, %ebp
128 ; CHECK-NEXT: jne .LBB0_15
129 ; CHECK-NEXT: # %bb.14: # %if.then31
130 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
131 ; CHECK-NEXT: xorl %ecx, %ecx
132 ; CHECK-NEXT: xorl %ebp, %ebp
133 ; CHECK-NEXT: jmp .LBB0_15
134 ; CHECK-NEXT: .p2align 4
135 ; CHECK-NEXT: .LBB0_9: # in Loop: Header=BB0_1 Depth=1
136 ; CHECK-NEXT: # implicit-def: $eax
137 ; CHECK-NEXT: testb %bl, %bl
138 ; CHECK-NEXT: je .LBB0_16
139 ; CHECK-NEXT: .LBB0_11: # in Loop: Header=BB0_1 Depth=1
140 ; CHECK-NEXT: # implicit-def: $edi
141 ; CHECK-NEXT: # implicit-def: $cl
142 ; CHECK-NEXT: # kill: killed $cl
143 ; CHECK-NEXT: # implicit-def: $dl
144 ; CHECK-NEXT: # implicit-def: $ebp
145 ; CHECK-NEXT: testl %edi, %edi
146 ; CHECK-NEXT: jne .LBB0_10
147 ; CHECK-NEXT: jmp .LBB0_6
151 for.cond: ; preds = %for.inc, %entry
152 %l.0 = phi i16 [ undef, %entry ], [ 0, %for.inc ]
153 %m.0 = phi i32 [ undef, %entry ], [ %m.2, %for.inc ]
154 %i.0 = phi i32 [ undef, %entry ], [ %i.2, %for.inc ]
155 %p.0 = phi i8 [ undef, %entry ], [ %p.2, %for.inc ]
156 %k.0 = phi i8 [ undef, %entry ], [ %k.2, %for.inc ]
157 %q.0 = phi i32 [ undef, %entry ], [ %q.2, %for.inc ]
158 %cmp = icmp ugt i8 %k.0, 8
159 %or.cond61 = or i1 %cmp, undef
160 br i1 %or.cond61, label %if.then, label %if.end
162 if.then: ; preds = %for.cond
163 tail call void (ptr, ...) @printf(ptr @.str, i64 undef)
166 if.end: ; preds = %for.cond
167 %0 = load i32, ptr @a, align 4
168 %div = sdiv i32 %m.0, %0
171 ac: ; preds = %ac, %if.end
172 br i1 undef, label %if.end9, label %ac
174 if.end9: ; preds = %ac
175 %conv3 = trunc i32 %m.0 to i8
176 %conv5 = sext i16 %l.0 to i32
177 store i32 %conv5, ptr @h, align 4
178 %cmp11 = icmp slt i8 %k.0, 9
179 br i1 %cmp11, label %if.then13, label %if.end21
181 if.then13: ; preds = %if.end9
182 tail call void (ptr, ...) @printf(ptr @.str, i64 undef)
183 br i1 undef, label %for.inc, label %for.cond35
185 if.end21: ; preds = %if.end9
186 %1 = load i8, ptr @g, align 1
189 ae: ; preds = %for.cond47, %if.end21
190 %l.2 = phi i16 [ undef, %if.end21 ], [ 0, %for.cond47 ]
191 %i.1 = phi i32 [ %i.0, %if.end21 ], [ %i.5, %for.cond47 ]
192 %p.1 = phi i8 [ %k.0, %if.end21 ], [ %p.6, %for.cond47 ]
193 %k.1 = phi i8 [ %conv3, %if.end21 ], [ %k.6, %for.cond47 ]
194 %q.1 = phi i32 [ undef, %if.end21 ], [ %q.5, %for.cond47 ]
195 br i1 undef, label %if.end26, label %af
197 if.end26: ; preds = %ae
198 %tobool27 = icmp eq i32 %q.1, 0
199 %tobool30 = icmp ne i8 %p.1, 0
200 %or.cond = and i1 %tobool30, %tobool27
201 br i1 %or.cond, label %if.then31, label %for.inc
203 if.then31: ; preds = %if.end26
206 for.inc: ; preds = %if.then31, %if.end26, %if.then13
207 %m.2 = phi i32 [ 0, %if.then31 ], [ 0, %if.end26 ], [ %div, %if.then13 ]
208 %i.2 = phi i32 [ %i.1, %if.then31 ], [ %i.1, %if.end26 ], [ %i.0, %if.then13 ]
209 %p.2 = phi i8 [ %p.1, %if.then31 ], [ %p.1, %if.end26 ], [ undef, %if.then13 ]
210 %k.2 = phi i8 [ %k.1, %if.then31 ], [ %k.1, %if.end26 ], [ %conv3, %if.then13 ]
211 %q.2 = phi i32 [ 0, %if.then31 ], [ %q.1, %if.end26 ], [ %q.0, %if.then13 ]
212 %2 = load i32, ptr @h, align 4
215 for.cond35: ; preds = %for.inc44, %if.then13, %if.then
216 %i.3 = phi i32 [ undef, %for.inc44 ], [ %i.0, %if.then ], [ %i.0, %if.then13 ]
217 %o.2 = phi i32 [ %o.3, %for.inc44 ], [ undef, %if.then ], [ undef, %if.then13 ]
218 %p.4 = phi i8 [ undef, %for.inc44 ], [ %p.0, %if.then ], [ %k.0, %if.then13 ]
219 %k.4 = phi i8 [ undef, %for.inc44 ], [ %k.0, %if.then ], [ %conv3, %if.then13 ]
220 %q.3 = phi i32 [ undef, %for.inc44 ], [ %q.0, %if.then ], [ %q.0, %if.then13 ]
221 %tobool36 = icmp eq i32 %i.3, 0
222 br i1 %tobool36, label %for.end46, label %af
224 af: ; preds = %for.cond35, %ae
225 %i.4 = phi i32 [ %i.3, %for.cond35 ], [ %i.1, %ae ]
226 %o.3 = phi i32 [ %o.2, %for.cond35 ], [ undef, %ae ]
227 br i1 undef, label %if.end39, label %for.inc44
229 if.end39: ; preds = %af
230 %tobool40 = icmp eq i32 %o.3, 0
231 br i1 %tobool40, label %for.end46, label %if.then41
233 if.then41: ; preds = %if.end39
234 tail call void (ptr, ...) @printf(ptr @.str, i64 ptrtoint (ptr @fn to i64))
237 for.inc44: ; preds = %af
240 for.end46: ; preds = %if.then41, %if.end39, %for.cond35
241 %i.5 = phi i32 [ %i.4, %if.then41 ], [ %i.4, %if.end39 ], [ 0, %for.cond35 ]
242 %p.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %p.4, %for.cond35 ]
243 %k.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %k.4, %for.cond35 ]
244 %q.5 = phi i32 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %q.3, %for.cond35 ]
247 for.cond47: ; preds = %for.cond47, %for.end46
248 %brmerge = or i1 false, undef
249 br i1 %brmerge, label %for.cond47, label %ae
252 declare dso_local void @printf(ptr nocapture readonly, ...) local_unnamed_addr
255 ; Testcase used to fail -verify-coalescing, reduced IR test which
257 define void @verifier_error_reduced_issue38788(i1 %cmp11) {
258 ; CHECK-LABEL: verifier_error_reduced_issue38788:
259 ; CHECK: # %bb.0: # %entry
260 ; CHECK-NEXT: pushl %ebx
261 ; CHECK-NEXT: .cfi_def_cfa_offset 8
262 ; CHECK-NEXT: .cfi_offset %ebx, -8
263 ; CHECK-NEXT: movzbl {{[0-9]+}}(%esp), %eax
264 ; CHECK-NEXT: xorl %ecx, %ecx
265 ; CHECK-NEXT: xorl %ebx, %ebx
266 ; CHECK-NEXT: jmp .LBB1_1
267 ; CHECK-NEXT: .p2align 4
268 ; CHECK-NEXT: .LBB1_7: # %if.end26
269 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
270 ; CHECK-NEXT: movl %ecx, %edx
271 ; CHECK-NEXT: .LBB1_8: # %for.inc
272 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
273 ; CHECK-NEXT: movl %eax, %ecx
274 ; CHECK-NEXT: movl %edx, %ebx
275 ; CHECK-NEXT: movzbl {{[0-9]+}}(%esp), %eax
276 ; CHECK-NEXT: .LBB1_1: # %for.cond
277 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
278 ; CHECK-NEXT: testb $1, %al
279 ; CHECK-NEXT: je .LBB1_3
280 ; CHECK-NEXT: # %bb.2: # in Loop: Header=BB1_1 Depth=1
281 ; CHECK-NEXT: xorl %eax, %eax
282 ; CHECK-NEXT: jmp .LBB1_5
283 ; CHECK-NEXT: .p2align 4
284 ; CHECK-NEXT: .LBB1_3: # %if.end
285 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
286 ; CHECK-NEXT: testb $1, %al
287 ; CHECK-NEXT: je .LBB1_4
288 ; CHECK-NEXT: # %bb.9: # %if.then13
289 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
290 ; CHECK-NEXT: xorl %edx, %edx
291 ; CHECK-NEXT: testb $1, %al
292 ; CHECK-NEXT: movl %ebx, %eax
293 ; CHECK-NEXT: movl $0, %ebx
294 ; CHECK-NEXT: jne .LBB1_8
295 ; CHECK-NEXT: jmp .LBB1_5
296 ; CHECK-NEXT: .p2align 4
297 ; CHECK-NEXT: .LBB1_4: # in Loop: Header=BB1_1 Depth=1
298 ; CHECK-NEXT: movl %ebx, %eax
299 ; CHECK-NEXT: xorl %ebx, %ebx
300 ; CHECK-NEXT: .LBB1_5: # %if.end26
301 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
302 ; CHECK-NEXT: testb %cl, %cl
303 ; CHECK-NEXT: je .LBB1_7
304 ; CHECK-NEXT: # %bb.6: # %if.end26
305 ; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
306 ; CHECK-NEXT: movl %ebx, %ecx
307 ; CHECK-NEXT: jmp .LBB1_7
311 for.cond: ; preds = %for.inc, %entry
312 %p.0 = phi i8 [ 0, %entry ], [ %p.2, %for.inc ]
313 %k.0 = phi i8 [ 0, %entry ], [ %k.2, %for.inc ]
314 br i1 %cmp11, label %for.cond35, label %if.end
316 if.end: ; preds = %for.cond
317 br i1 %cmp11, label %if.then13, label %if.end26
319 if.then13: ; preds = %if.end
320 br i1 %cmp11, label %for.inc, label %for.cond35
322 if.end26: ; preds = %for.cond35, %if.end
323 %p.1 = phi i8 [ %p.4, %for.cond35 ], [ %k.0, %if.end ]
324 %k.1 = phi i8 [ %k.4, %for.cond35 ], [ 0, %if.end ]
325 %tobool30 = icmp ne i8 %p.0, 0
326 %spec.select1 = select i1 %tobool30, i8 %k.1, i8 0
329 for.inc: ; preds = %if.end26, %if.then13
330 %p.2 = phi i8 [ poison, %if.then13 ], [ %p.1, %if.end26 ]
331 %k.2 = phi i8 [ 0, %if.then13 ], [ %spec.select1, %if.end26 ]
332 %0 = load i32, ptr null, align 4
335 for.cond35: ; preds = %if.then13, %for.cond
336 %p.4 = phi i8 [ %k.0, %if.then13 ], [ 0, %for.cond ]
337 %k.4 = phi i8 [ 0, %if.then13 ], [ %k.0, %for.cond ]
338 %tobool36 = icmp eq i32 0, 0