1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
4 ; Function Attrs: nounwind uwtable
5 define void @tail_dup_merge_loops(i32 %a, i8* %b, i8* %c) local_unnamed_addr #0 {
6 ; CHECK-LABEL: tail_dup_merge_loops:
7 ; CHECK: # %bb.0: # %entry
8 ; CHECK-NEXT: jmp .LBB0_1
9 ; CHECK-NEXT: .p2align 4, 0x90
10 ; CHECK-NEXT: .LBB0_3: # %inner_loop_exit
11 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
12 ; CHECK-NEXT: incq %rsi
13 ; CHECK-NEXT: .LBB0_1: # %outer_loop_top
14 ; CHECK-NEXT: # =>This Loop Header: Depth=1
15 ; CHECK-NEXT: # Child Loop BB0_4 Depth 2
16 ; CHECK-NEXT: testl %edi, %edi
17 ; CHECK-NEXT: je .LBB0_5
18 ; CHECK-NEXT: .p2align 4, 0x90
19 ; CHECK-NEXT: # %bb.2: # %inner_loop_top
20 ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
21 ; CHECK-NEXT: cmpb $0, (%rsi)
22 ; CHECK-NEXT: js .LBB0_3
23 ; CHECK-NEXT: .LBB0_4: # %inner_loop_latch
24 ; CHECK-NEXT: # Parent Loop BB0_1 Depth=1
25 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
26 ; CHECK-NEXT: addq $2, %rsi
27 ; CHECK-NEXT: cmpb $0, (%rsi)
28 ; CHECK-NEXT: jns .LBB0_4
29 ; CHECK-NEXT: jmp .LBB0_3
30 ; CHECK-NEXT: .LBB0_5: # %exit
33 %notlhs674.i = icmp eq i32 %a, 0
34 br label %outer_loop_top
36 outer_loop_top: ; preds = %inner_loop_exit, %entry
37 %dst.0.ph.i = phi i8* [ %b, %entry ], [ %scevgep679.i, %inner_loop_exit ]
38 br i1 %notlhs674.i, label %exit, label %inner_loop_preheader
40 inner_loop_preheader: ; preds = %outer_loop_top
41 br label %inner_loop_top
43 inner_loop_top: ; preds = %inner_loop_latch, %inner_loop_preheader
44 %dst.0.i = phi i8* [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ]
45 %var = load i8, i8* %dst.0.i
46 %tobool1.i = icmp slt i8 %var, 0
47 br label %inner_loop_test
49 inner_loop_test: ; preds = %inner_loop_top
50 br i1 %tobool1.i, label %inner_loop_exit, label %inner_loop_latch
52 inner_loop_exit: ; preds = %inner_loop_test
53 %scevgep.i = getelementptr i8, i8* %dst.0.i, i64 1
54 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 0
55 br label %outer_loop_top
57 inner_loop_latch: ; preds = %inner_loop_test
58 %cmp75.i = icmp ult i8* %dst.0.i, %c
59 %inc = getelementptr i8, i8* %dst.0.i, i64 2
60 br label %inner_loop_top
62 exit: ; preds = %outer_loop_top
66 @.str.6 = external unnamed_addr constant [23 x i8], align 1
68 ; There is an erroneus check in LoopBase::addBasicBlockToLoop(), where it
69 ; assumes that the header block for a loop is unique.
70 ; For most of compilation this assumption is true, but during layout we allow
71 ; this assumption to be violated. The following code will trigger the bug:
73 ; The loops in question is eventually headed by the block shared_loop_header
75 ; During layout The block labeled outer_loop_header gets tail-duplicated into
76 ; outer_loop_latch, and into shared_preheader, and then removed. This leaves
77 ; shared_loop_header as the header of both loops. The end result
78 ; is that there are 2 valid loops, and that they share a header. If we re-ran
79 ; the loop analysis, it would classify this as a single loop.
80 ; So far this is fine as far as layout is concerned.
81 ; After layout we tail merge blocks merge_other and merge_predecessor_split.
82 ; We do this even though they share only a single instruction, because
83 ; merge_predecessor_split falls through to their shared successor:
85 ; The rest of the blocks in the function are noise unfortunately. Bugpoint
86 ; couldn't shrink the test any further.
88 define i32 @loop_shared_header(i8* %exe, i32 %exesz, i32 %headsize, i32 %min, i32 %wwprva, i32 %e_lfanew, i8* readonly %wwp, i32 %wwpsz, i16 zeroext %sects) local_unnamed_addr #0 {
89 ; CHECK-LABEL: loop_shared_header:
90 ; CHECK: # %bb.0: # %entry
91 ; CHECK-NEXT: pushq %rbp
92 ; CHECK-NEXT: pushq %r15
93 ; CHECK-NEXT: pushq %r14
94 ; CHECK-NEXT: pushq %r13
95 ; CHECK-NEXT: pushq %r12
96 ; CHECK-NEXT: pushq %rbx
97 ; CHECK-NEXT: pushq %rax
98 ; CHECK-NEXT: movl $1, %ebx
99 ; CHECK-NEXT: xorl %eax, %eax
100 ; CHECK-NEXT: testb %al, %al
101 ; CHECK-NEXT: jne .LBB1_24
102 ; CHECK-NEXT: # %bb.1: # %if.end19
103 ; CHECK-NEXT: movl %esi, %ebp
104 ; CHECK-NEXT: movq %rdi, %r15
105 ; CHECK-NEXT: movl (%rax), %r13d
106 ; CHECK-NEXT: leal (,%r13,4), %ebx
107 ; CHECK-NEXT: movl %ebx, %r12d
108 ; CHECK-NEXT: movl $1, %esi
109 ; CHECK-NEXT: movq %r12, %rdi
110 ; CHECK-NEXT: callq cli_calloc@PLT
111 ; CHECK-NEXT: testl %ebp, %ebp
112 ; CHECK-NEXT: je .LBB1_23
113 ; CHECK-NEXT: # %bb.2: # %if.end19
114 ; CHECK-NEXT: testl %r13d, %r13d
115 ; CHECK-NEXT: je .LBB1_23
116 ; CHECK-NEXT: # %bb.3: # %if.end19
117 ; CHECK-NEXT: movq %rax, %r14
118 ; CHECK-NEXT: xorl %eax, %eax
119 ; CHECK-NEXT: testb %al, %al
120 ; CHECK-NEXT: jne .LBB1_23
121 ; CHECK-NEXT: # %bb.4: # %if.end19
122 ; CHECK-NEXT: cmpq %r15, %r14
123 ; CHECK-NEXT: jb .LBB1_23
124 ; CHECK-NEXT: # %bb.5: # %if.end50
125 ; CHECK-NEXT: movq %r14, %rdi
126 ; CHECK-NEXT: movq %r12, %rdx
127 ; CHECK-NEXT: callq memcpy@PLT
128 ; CHECK-NEXT: cmpl $4, %ebx
129 ; CHECK-NEXT: jb .LBB1_26
130 ; CHECK-NEXT: # %bb.6: # %shared_preheader
131 ; CHECK-NEXT: movb $32, %cl
132 ; CHECK-NEXT: xorl %eax, %eax
133 ; CHECK-NEXT: jmp .LBB1_8
134 ; CHECK-NEXT: .p2align 4, 0x90
135 ; CHECK-NEXT: .LBB1_7: # %merge_predecessor_split
136 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
137 ; CHECK-NEXT: movb $32, %cl
138 ; CHECK-NEXT: .LBB1_8: # %outer_loop_header
139 ; CHECK-NEXT: # =>This Loop Header: Depth=1
140 ; CHECK-NEXT: # Child Loop BB1_9 Depth 2
141 ; CHECK-NEXT: testl %r13d, %r13d
142 ; CHECK-NEXT: je .LBB1_16
143 ; CHECK-NEXT: .p2align 4, 0x90
144 ; CHECK-NEXT: .LBB1_9: # %shared_loop_header
145 ; CHECK-NEXT: # Parent Loop BB1_8 Depth=1
146 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
147 ; CHECK-NEXT: testq %r14, %r14
148 ; CHECK-NEXT: jne .LBB1_25
149 ; CHECK-NEXT: # %bb.10: # %inner_loop_body
150 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=2
151 ; CHECK-NEXT: testb %al, %al
152 ; CHECK-NEXT: je .LBB1_9
153 ; CHECK-NEXT: # %bb.11: # %if.end96.i
154 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
155 ; CHECK-NEXT: cmpl $3, %r13d
156 ; CHECK-NEXT: jae .LBB1_20
157 ; CHECK-NEXT: # %bb.12: # %if.end287.i
158 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
159 ; CHECK-NEXT: testb %al, %al
160 ; CHECK-NEXT: # implicit-def: $cl
161 ; CHECK-NEXT: jne .LBB1_8
162 ; CHECK-NEXT: # %bb.13: # %if.end308.i
163 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
164 ; CHECK-NEXT: testb %al, %al
165 ; CHECK-NEXT: je .LBB1_7
166 ; CHECK-NEXT: # %bb.14: # %if.end335.i
167 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
168 ; CHECK-NEXT: xorl %ecx, %ecx
169 ; CHECK-NEXT: testb %cl, %cl
170 ; CHECK-NEXT: jne .LBB1_8
171 ; CHECK-NEXT: # %bb.15: # %merge_other
172 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1
173 ; CHECK-NEXT: # implicit-def: $cl
174 ; CHECK-NEXT: jmp .LBB1_8
175 ; CHECK-NEXT: .LBB1_23:
176 ; CHECK-NEXT: movl $1, %ebx
177 ; CHECK-NEXT: jmp .LBB1_24
178 ; CHECK-NEXT: .LBB1_16: # %while.cond.us1412.i
179 ; CHECK-NEXT: xorl %eax, %eax
180 ; CHECK-NEXT: testb %al, %al
181 ; CHECK-NEXT: movl $1, %ebx
182 ; CHECK-NEXT: jne .LBB1_18
183 ; CHECK-NEXT: # %bb.17: # %while.cond.us1412.i
184 ; CHECK-NEXT: decb %cl
185 ; CHECK-NEXT: jne .LBB1_24
186 ; CHECK-NEXT: .LBB1_18: # %if.end41.us1436.i
187 ; CHECK-NEXT: .LBB1_20: # %if.then99.i
188 ; CHECK-NEXT: movq .str.6@GOTPCREL(%rip), %rdi
189 ; CHECK-NEXT: xorl %ebx, %ebx
190 ; CHECK-NEXT: xorl %eax, %eax
191 ; CHECK-NEXT: callq cli_dbgmsg@PLT
192 ; CHECK-NEXT: .LBB1_24: # %cleanup
193 ; CHECK-NEXT: movl %ebx, %eax
194 ; CHECK-NEXT: addq $8, %rsp
195 ; CHECK-NEXT: popq %rbx
196 ; CHECK-NEXT: popq %r12
197 ; CHECK-NEXT: popq %r13
198 ; CHECK-NEXT: popq %r14
199 ; CHECK-NEXT: popq %r15
200 ; CHECK-NEXT: popq %rbp
202 ; CHECK-NEXT: .LBB1_25: # %wunpsect.exit.thread.loopexit389
203 ; CHECK-NEXT: .LBB1_26: # %wunpsect.exit.thread.loopexit391
205 %0 = load i32, i32* undef, align 4
206 %mul = shl nsw i32 %0, 2
207 br i1 undef, label %if.end19, label %cleanup
209 if.end19: ; preds = %entry
210 %conv = zext i32 %mul to i64
211 %call = tail call i8* @cli_calloc(i64 %conv, i64 1)
212 %1 = icmp eq i32 %exesz, 0
213 %notrhs = icmp eq i32 %0, 0
214 %or.cond117.not = or i1 %1, %notrhs
215 %or.cond202 = or i1 %or.cond117.not, undef
216 %cmp35 = icmp ult i8* %call, %exe
217 %or.cond203 = or i1 %or.cond202, %cmp35
218 br i1 %or.cond203, label %cleanup, label %if.end50
220 if.end50: ; preds = %if.end19
221 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i1 false)
222 %cmp1.i.i = icmp ugt i32 %mul, 3
223 br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391
225 shared_preheader: ; preds = %if.end50
226 br label %outer_loop_header
228 outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader
229 %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ]
230 %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ]
231 %2 = icmp eq i32 %0, 0
232 br i1 %2, label %while.cond.us1412.i, label %shared_loop_header
234 while.cond.us1412.i: ; preds = %outer_loop_header
235 %.pre.i = add i8 %bits.1.i, -1
236 %tobool2.us1420.i = icmp eq i8 %.pre.i, 0
237 %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i
238 br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup
240 if.end41.us1436.i: ; preds = %while.cond.us1412.i
243 shared_loop_header: ; preds = %dup_early2, %dup_early1
244 %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ]
245 %cmp3.i1172.i = icmp ult i8* null, %call
246 br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body
248 inner_loop_body: ; preds = %shared_loop_header
249 %3 = icmp slt i32 undef, 0
250 br i1 %3, label %if.end96.i, label %shared_loop_header
252 dead_block: ; preds = %inner_loop_body
253 %cmp75.i = icmp ult i8* %dst.0.i, null
254 br label %shared_loop_header
256 if.end96.i: ; preds = %inner_loop_body
257 %cmp97.i = icmp ugt i32 %0, 2
258 br i1 %cmp97.i, label %if.then99.i, label %if.end287.i
260 if.then99.i: ; preds = %if.end96.i
261 tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef)
264 if.end287.i: ; preds = %if.end96.i
265 %cmp291.i = icmp ne i32 %0, 1
266 %conv294.i = select i1 %cmp291.i, i16 4, i16 3
267 br i1 undef, label %if.end308.i, label %outer_loop_latch
269 if.end308.i: ; preds = %if.end287.i
270 br i1 undef, label %if.end335.i, label %merge_predecessor_split
272 merge_predecessor_split: ; preds = %if.end308.i
273 %4 = bitcast i8* undef to i32*
274 br label %outer_loop_latch
276 if.end335.i: ; preds = %if.end308.i
277 br i1 undef, label %outer_loop_latch, label %merge_other
279 merge_other: ; preds = %if.end335.i
280 br label %outer_loop_latch
282 outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i
283 %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ]
284 %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ]
285 %5 = add i16 %backsize.0.i, -1
286 %6 = zext i16 %5 to i64
287 %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1
288 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6
289 br label %outer_loop_header
291 wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header
294 wunpsect.exit.thread.loopexit391: ; preds = %if.end50
297 cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry
298 %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ]
302 ; Function Attrs: nounwind
303 declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0
305 ; Function Attrs: nounwind
306 declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0
308 ; Function Attrs: argmemonly nounwind
309 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
310 attributes #0 = { nounwind }
311 attributes #1 = { argmemonly nounwind }