1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39440.
3; RUN: llc %s -O2 -mtriple=i386-unknown-linux-gnu -o - -verify-machineinstrs=0 | FileCheck %s
4@.str = external dso_local unnamed_addr constant [6 x i8], align 1
5@a = external dso_local local_unnamed_addr global i32, align 4
6@h = external dso_local local_unnamed_addr global i32, align 4
7@g = external dso_local local_unnamed_addr global i8, align 1
8
9define dso_local void @fn() {
10; CHECK-LABEL: fn:
11; CHECK:       # %bb.0: # %entry
12; CHECK-NEXT:    pushl %ebp
13; CHECK-NEXT:    .cfi_def_cfa_offset 8
14; CHECK-NEXT:    pushl %ebx
15; CHECK-NEXT:    .cfi_def_cfa_offset 12
16; CHECK-NEXT:    pushl %edi
17; CHECK-NEXT:    .cfi_def_cfa_offset 16
18; CHECK-NEXT:    pushl %esi
19; CHECK-NEXT:    .cfi_def_cfa_offset 20
20; CHECK-NEXT:    subl $28, %esp
21; CHECK-NEXT:    .cfi_def_cfa_offset 48
22; CHECK-NEXT:    .cfi_offset %esi, -20
23; CHECK-NEXT:    .cfi_offset %edi, -16
24; CHECK-NEXT:    .cfi_offset %ebx, -12
25; CHECK-NEXT:    .cfi_offset %ebp, -8
26; CHECK-NEXT:    xorl %ebx, %ebx
27; CHECK-NEXT:    # implicit-def: $ecx
28; CHECK-NEXT:    # implicit-def: $edi
29; CHECK-NEXT:    # implicit-def: $al
30; CHECK-NEXT:    # kill: killed $al
31; CHECK-NEXT:    # implicit-def: $dl
32; CHECK-NEXT:    # implicit-def: $ebp
33; CHECK-NEXT:    jmp .LBB0_1
34; CHECK-NEXT:    .p2align 4, 0x90
35; CHECK-NEXT:  .LBB0_16: # %for.inc
36; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
37; CHECK-NEXT:    movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
38; CHECK-NEXT:    movb %dh, %dl
39; CHECK-NEXT:  .LBB0_1: # %for.cond
40; CHECK-NEXT:    # =>This Loop Header: Depth=1
41; CHECK-NEXT:    # Child Loop BB0_20 Depth 2
42; CHECK-NEXT:    cmpb $8, %dl
43; CHECK-NEXT:    movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
44; CHECK-NEXT:    ja .LBB0_3
45; CHECK-NEXT:  # %bb.2: # %for.cond
46; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
47; CHECK-NEXT:    testb %bl, %bl
48; CHECK-NEXT:    je .LBB0_3
49; CHECK-NEXT:  # %bb.4: # %if.end
50; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
51; CHECK-NEXT:    movl %ecx, %eax
52; CHECK-NEXT:    cltd
53; CHECK-NEXT:    idivl a
54; CHECK-NEXT:    movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
55; CHECK-NEXT:    movb %cl, %dh
56; CHECK-NEXT:    movl $0, h
57; CHECK-NEXT:    cmpb $8, %dl
58; CHECK-NEXT:    jg .LBB0_8
59; CHECK-NEXT:  # %bb.5: # %if.then13
60; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
61; CHECK-NEXT:    movl %eax, %esi
62; CHECK-NEXT:    movl $.str, (%esp)
63; CHECK-NEXT:    movb %dh, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
64; CHECK-NEXT:    calll printf
65; CHECK-NEXT:    movb {{[-0-9]+}}(%e{{[sb]}}p), %dh # 1-byte Reload
66; CHECK-NEXT:    testb %bl, %bl
67; CHECK-NEXT:    movl %esi, %ecx
68; CHECK-NEXT:    # implicit-def: $eax
69; CHECK-NEXT:    movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
70; CHECK-NEXT:    movb %dl, {{[-0-9]+}}(%e{{[sb]}}p) # 1-byte Spill
71; CHECK-NEXT:    movb %dh, %dl
72; CHECK-NEXT:    jne .LBB0_16
73; CHECK-NEXT:    jmp .LBB0_6
74; CHECK-NEXT:    .p2align 4, 0x90
75; CHECK-NEXT:  .LBB0_3: # %if.then
76; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
77; CHECK-NEXT:    movl $.str, (%esp)
78; CHECK-NEXT:    calll printf
79; CHECK-NEXT:    movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
80; CHECK-NEXT:    # implicit-def: $eax
81; CHECK-NEXT:  .LBB0_6: # %for.cond35
82; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
83; CHECK-NEXT:    testl %edi, %edi
84; CHECK-NEXT:    je .LBB0_7
85; CHECK-NEXT:  .LBB0_11: # %af
86; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
87; CHECK-NEXT:    testb %bl, %bl
88; CHECK-NEXT:    jne .LBB0_12
89; CHECK-NEXT:  .LBB0_17: # %if.end39
90; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
91; CHECK-NEXT:    testl %eax, %eax
92; CHECK-NEXT:    je .LBB0_19
93; CHECK-NEXT:  # %bb.18: # %if.then41
94; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
95; CHECK-NEXT:    movl $0, {{[0-9]+}}(%esp)
96; CHECK-NEXT:    movl $fn, {{[0-9]+}}(%esp)
97; CHECK-NEXT:    movl $.str, (%esp)
98; CHECK-NEXT:    calll printf
99; CHECK-NEXT:  .LBB0_19: # %for.end46
100; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
101; CHECK-NEXT:    # implicit-def: $dl
102; CHECK-NEXT:    # implicit-def: $dh
103; CHECK-NEXT:    # implicit-def: $ebp
104; CHECK-NEXT:    jmp .LBB0_20
105; CHECK-NEXT:    .p2align 4, 0x90
106; CHECK-NEXT:  .LBB0_8: # %if.end21
107; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
108; CHECK-NEXT:    # implicit-def: $ebp
109; CHECK-NEXT:    jmp .LBB0_9
110; CHECK-NEXT:    .p2align 4, 0x90
111; CHECK-NEXT:  .LBB0_7: # in Loop: Header=BB0_1 Depth=1
112; CHECK-NEXT:    xorl %edi, %edi
113; CHECK-NEXT:    movb %dl, %dh
114; CHECK-NEXT:    movb {{[-0-9]+}}(%e{{[sb]}}p), %dl # 1-byte Reload
115; CHECK-NEXT:    .p2align 4, 0x90
116; CHECK-NEXT:  .LBB0_20: # %for.cond47
117; CHECK-NEXT:    # Parent Loop BB0_1 Depth=1
118; CHECK-NEXT:    # => This Inner Loop Header: Depth=2
119; CHECK-NEXT:    testb %bl, %bl
120; CHECK-NEXT:    jne .LBB0_20
121; CHECK-NEXT:  # %bb.21: # %for.cond47
122; CHECK-NEXT:    # in Loop: Header=BB0_20 Depth=2
123; CHECK-NEXT:    testb %bl, %bl
124; CHECK-NEXT:    jne .LBB0_20
125; CHECK-NEXT:  .LBB0_9: # %ae
126; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
127; CHECK-NEXT:    testb %bl, %bl
128; CHECK-NEXT:    jne .LBB0_10
129; CHECK-NEXT:  # %bb.13: # %if.end26
130; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
131; CHECK-NEXT:    xorl %ecx, %ecx
132; CHECK-NEXT:    testb %dl, %dl
133; CHECK-NEXT:    je .LBB0_16
134; CHECK-NEXT:  # %bb.14: # %if.end26
135; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
136; CHECK-NEXT:    testl %ebp, %ebp
137; CHECK-NEXT:    jne .LBB0_16
138; CHECK-NEXT:  # %bb.15: # %if.then31
139; CHECK-NEXT:    # in Loop: Header=BB0_1 Depth=1
140; CHECK-NEXT:    xorl %ecx, %ecx
141; CHECK-NEXT:    xorl %ebp, %ebp
142; CHECK-NEXT:    jmp .LBB0_16
143; CHECK-NEXT:    .p2align 4, 0x90
144; CHECK-NEXT:  .LBB0_10: # in Loop: Header=BB0_1 Depth=1
145; CHECK-NEXT:    # implicit-def: $eax
146; CHECK-NEXT:    testb %bl, %bl
147; CHECK-NEXT:    je .LBB0_17
148; CHECK-NEXT:  .LBB0_12: # in Loop: Header=BB0_1 Depth=1
149; CHECK-NEXT:    # implicit-def: $edi
150; CHECK-NEXT:    # implicit-def: $cl
151; CHECK-NEXT:    # kill: killed $cl
152; CHECK-NEXT:    # implicit-def: $dl
153; CHECK-NEXT:    # implicit-def: $ebp
154; CHECK-NEXT:    testl %edi, %edi
155; CHECK-NEXT:    jne .LBB0_11
156; CHECK-NEXT:    jmp .LBB0_7
157entry:
158  br label %for.cond
159
160for.cond:                                         ; preds = %for.inc, %entry
161  %l.0 = phi i16 [ undef, %entry ], [ 0, %for.inc ]
162  %m.0 = phi i32 [ undef, %entry ], [ %m.2, %for.inc ]
163  %i.0 = phi i32 [ undef, %entry ], [ %i.2, %for.inc ]
164  %p.0 = phi i8 [ undef, %entry ], [ %p.2, %for.inc ]
165  %k.0 = phi i8 [ undef, %entry ], [ %k.2, %for.inc ]
166  %q.0 = phi i32 [ undef, %entry ], [ %q.2, %for.inc ]
167  %cmp = icmp ugt i8 %k.0, 8
168  %or.cond61 = or i1 %cmp, undef
169  br i1 %or.cond61, label %if.then, label %if.end
170
171if.then:                                          ; preds = %for.cond
172  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i64 undef)
173  br label %for.cond35
174
175if.end:                                           ; preds = %for.cond
176  %0 = load i32, i32* @a, align 4
177  %div = sdiv i32 %m.0, %0
178  br label %ac
179
180ac:                                               ; preds = %ac, %if.end
181  br i1 undef, label %if.end9, label %ac
182
183if.end9:                                          ; preds = %ac
184  %conv3 = trunc i32 %m.0 to i8
185  %conv5 = sext i16 %l.0 to i32
186  store i32 %conv5, i32* @h, align 4
187  %cmp11 = icmp slt i8 %k.0, 9
188  br i1 %cmp11, label %if.then13, label %if.end21
189
190if.then13:                                        ; preds = %if.end9
191  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i64 undef)
192  br i1 undef, label %for.inc, label %for.cond35
193
194if.end21:                                         ; preds = %if.end9
195  %1 = load i8, i8* @g, align 1
196  br label %ae
197
198ae:                                               ; preds = %for.cond47, %if.end21
199  %l.2 = phi i16 [ undef, %if.end21 ], [ 0, %for.cond47 ]
200  %i.1 = phi i32 [ %i.0, %if.end21 ], [ %i.5, %for.cond47 ]
201  %p.1 = phi i8 [ %k.0, %if.end21 ], [ %p.6, %for.cond47 ]
202  %k.1 = phi i8 [ %conv3, %if.end21 ], [ %k.6, %for.cond47 ]
203  %q.1 = phi i32 [ undef, %if.end21 ], [ %q.5, %for.cond47 ]
204  br i1 undef, label %if.end26, label %af
205
206if.end26:                                         ; preds = %ae
207  %tobool27 = icmp eq i32 %q.1, 0
208  %tobool30 = icmp ne i8 %p.1, 0
209  %or.cond = and i1 %tobool30, %tobool27
210  br i1 %or.cond, label %if.then31, label %for.inc
211
212if.then31:                                        ; preds = %if.end26
213  br label %for.inc
214
215for.inc:                                          ; preds = %if.then31, %if.end26, %if.then13
216  %m.2 = phi i32 [ 0, %if.then31 ], [ 0, %if.end26 ], [ %div, %if.then13 ]
217  %i.2 = phi i32 [ %i.1, %if.then31 ], [ %i.1, %if.end26 ], [ %i.0, %if.then13 ]
218  %p.2 = phi i8 [ %p.1, %if.then31 ], [ %p.1, %if.end26 ], [ undef, %if.then13 ]
219  %k.2 = phi i8 [ %k.1, %if.then31 ], [ %k.1, %if.end26 ], [ %conv3, %if.then13 ]
220  %q.2 = phi i32 [ 0, %if.then31 ], [ %q.1, %if.end26 ], [ %q.0, %if.then13 ]
221  %2 = load i32, i32* @h, align 4
222  br label %for.cond
223
224for.cond35:                                       ; preds = %for.inc44, %if.then13, %if.then
225  %i.3 = phi i32 [ undef, %for.inc44 ], [ %i.0, %if.then ], [ %i.0, %if.then13 ]
226  %o.2 = phi i32 [ %o.3, %for.inc44 ], [ undef, %if.then ], [ undef, %if.then13 ]
227  %p.4 = phi i8 [ undef, %for.inc44 ], [ %p.0, %if.then ], [ %k.0, %if.then13 ]
228  %k.4 = phi i8 [ undef, %for.inc44 ], [ %k.0, %if.then ], [ %conv3, %if.then13 ]
229  %q.3 = phi i32 [ undef, %for.inc44 ], [ %q.0, %if.then ], [ %q.0, %if.then13 ]
230  %tobool36 = icmp eq i32 %i.3, 0
231  br i1 %tobool36, label %for.end46, label %af
232
233af:                                               ; preds = %for.cond35, %ae
234  %i.4 = phi i32 [ %i.3, %for.cond35 ], [ %i.1, %ae ]
235  %o.3 = phi i32 [ %o.2, %for.cond35 ], [ undef, %ae ]
236  br i1 undef, label %if.end39, label %for.inc44
237
238if.end39:                                         ; preds = %af
239  %tobool40 = icmp eq i32 %o.3, 0
240  br i1 %tobool40, label %for.end46, label %if.then41
241
242if.then41:                                        ; preds = %if.end39
243  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i64 ptrtoint (void ()* @fn to i64))
244  br label %for.end46
245
246for.inc44:                                        ; preds = %af
247  br label %for.cond35
248
249for.end46:                                        ; preds = %if.then41, %if.end39, %for.cond35
250  %i.5 = phi i32 [ %i.4, %if.then41 ], [ %i.4, %if.end39 ], [ 0, %for.cond35 ]
251  %p.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %p.4, %for.cond35 ]
252  %k.6 = phi i8 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %k.4, %for.cond35 ]
253  %q.5 = phi i32 [ undef, %if.then41 ], [ undef, %if.end39 ], [ %q.3, %for.cond35 ]
254  br label %for.cond47
255
256for.cond47:                                       ; preds = %for.cond47, %for.end46
257  %brmerge = or i1 false, undef
258  br i1 %brmerge, label %for.cond47, label %ae
259}
260
261declare dso_local void @printf(i8* nocapture readonly, ...) local_unnamed_addr
262