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: testl %edi, %edi
9 ; CHECK-NEXT: jne .LBB0_2
10 ; CHECK-NEXT: jmp .LBB0_5
11 ; CHECK-NEXT: .LBB0_3: # %inner_loop_exit
12 ; CHECK-NEXT: # in Loop: Header=BB0_2 Depth=1
13 ; CHECK-NEXT: incq %rsi
14 ; CHECK-NEXT: testl %edi, %edi
15 ; CHECK-NEXT: je .LBB0_5
16 ; CHECK-NEXT: .p2align 4, 0x90
17 ; CHECK-NEXT: .LBB0_2: # %inner_loop_top
18 ; CHECK-NEXT: # =>This Loop Header: Depth=1
19 ; CHECK-NEXT: # Child Loop BB0_4 Depth 2
20 ; CHECK-NEXT: cmpb $0, (%rsi)
21 ; CHECK-NEXT: js .LBB0_3
22 ; CHECK-NEXT: .LBB0_4: # %inner_loop_latch
23 ; CHECK-NEXT: # Parent Loop BB0_2 Depth=1
24 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
25 ; CHECK-NEXT: addq $2, %rsi
26 ; CHECK-NEXT: cmpb $0, (%rsi)
27 ; CHECK-NEXT: jns .LBB0_4
28 ; CHECK-NEXT: jmp .LBB0_3
29 ; CHECK-NEXT: .LBB0_5: # %exit
32 %notlhs674.i = icmp eq i32 %a, 0
33 br label %outer_loop_top
35 outer_loop_top: ; preds = %inner_loop_exit, %entry
36 %dst.0.ph.i = phi i8* [ %b, %entry ], [ %scevgep679.i, %inner_loop_exit ]
37 br i1 %notlhs674.i, label %exit, label %inner_loop_preheader
39 inner_loop_preheader: ; preds = %outer_loop_top
40 br label %inner_loop_top
42 inner_loop_top: ; preds = %inner_loop_latch, %inner_loop_preheader
43 %dst.0.i = phi i8* [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ]
44 %var = load i8, i8* %dst.0.i
45 %tobool1.i = icmp slt i8 %var, 0
46 br label %inner_loop_test
48 inner_loop_test: ; preds = %inner_loop_top
49 br i1 %tobool1.i, label %inner_loop_exit, label %inner_loop_latch
51 inner_loop_exit: ; preds = %inner_loop_test
52 %scevgep.i = getelementptr i8, i8* %dst.0.i, i64 1
53 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 0
54 br label %outer_loop_top
56 inner_loop_latch: ; preds = %inner_loop_test
57 %cmp75.i = icmp ult i8* %dst.0.i, %c
58 %inc = getelementptr i8, i8* %dst.0.i, i64 2
59 br label %inner_loop_top
61 exit: ; preds = %outer_loop_top
65 @.str.6 = external unnamed_addr constant [23 x i8], align 1
67 ; There is an erroneus check in LoopBase::addBasicBlockToLoop(), where it
68 ; assumes that the header block for a loop is unique.
69 ; For most of compilation this assumption is true, but during layout we allow
70 ; this assumption to be violated. The following code will trigger the bug:
72 ; The loops in question is eventually headed by the block shared_loop_header
74 ; During layout The block labeled outer_loop_header gets tail-duplicated into
75 ; outer_loop_latch, and into shared_preheader, and then removed. This leaves
76 ; shared_loop_header as the header of both loops. The end result
77 ; is that there are 2 valid loops, and that they share a header. If we re-ran
78 ; the loop analysis, it would classify this as a single loop.
79 ; So far this is fine as far as layout is concerned.
80 ; After layout we tail merge blocks merge_other and merge_predecessor_split.
81 ; We do this even though they share only a single instruction, because
82 ; merge_predecessor_split falls through to their shared successor:
84 ; The rest of the blocks in the function are noise unfortunately. Bugpoint
85 ; couldn't shrink the test any further.
87 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 {
88 ; CHECK-LABEL: loop_shared_header:
89 ; CHECK: # %bb.0: # %entry
90 ; CHECK-NEXT: pushq %rbp
91 ; CHECK-NEXT: pushq %r15
92 ; CHECK-NEXT: pushq %r14
93 ; CHECK-NEXT: pushq %r13
94 ; CHECK-NEXT: pushq %r12
95 ; CHECK-NEXT: pushq %rbx
96 ; CHECK-NEXT: pushq %rax
97 ; CHECK-NEXT: movl $1, %ebx
98 ; CHECK-NEXT: xorl %eax, %eax
99 ; CHECK-NEXT: testb %al, %al
100 ; CHECK-NEXT: jne .LBB1_26
101 ; CHECK-NEXT: # %bb.1: # %if.end19
102 ; CHECK-NEXT: movl %esi, %r13d
103 ; CHECK-NEXT: movq %rdi, %r12
104 ; CHECK-NEXT: movl (%rax), %ebp
105 ; CHECK-NEXT: leal (,%rbp,4), %r14d
106 ; CHECK-NEXT: movl %r14d, %r15d
107 ; CHECK-NEXT: movl $1, %esi
108 ; CHECK-NEXT: movq %r15, %rdi
109 ; CHECK-NEXT: callq cli_calloc
110 ; CHECK-NEXT: testl %r13d, %r13d
111 ; CHECK-NEXT: je .LBB1_25
112 ; CHECK-NEXT: # %bb.2: # %if.end19
113 ; CHECK-NEXT: testl %ebp, %ebp
114 ; CHECK-NEXT: je .LBB1_25
115 ; CHECK-NEXT: # %bb.3: # %if.end19
116 ; CHECK-NEXT: movq %rax, %rbx
117 ; CHECK-NEXT: xorl %eax, %eax
118 ; CHECK-NEXT: testb %al, %al
119 ; CHECK-NEXT: jne .LBB1_25
120 ; CHECK-NEXT: # %bb.4: # %if.end19
121 ; CHECK-NEXT: cmpq %r12, %rbx
122 ; CHECK-NEXT: jb .LBB1_25
123 ; CHECK-NEXT: # %bb.5: # %if.end50
124 ; CHECK-NEXT: movq %rbx, %rdi
125 ; CHECK-NEXT: movq %r15, %rdx
126 ; CHECK-NEXT: callq memcpy
127 ; CHECK-NEXT: cmpl $4, %r14d
128 ; CHECK-NEXT: jb .LBB1_28
129 ; CHECK-NEXT: # %bb.6: # %shared_preheader
130 ; CHECK-NEXT: movb $32, %dl
131 ; CHECK-NEXT: xorl %eax, %eax
132 ; CHECK-NEXT: # implicit-def: $rcx
133 ; CHECK-NEXT: testl %ebp, %ebp
134 ; CHECK-NEXT: je .LBB1_18
135 ; CHECK-NEXT: .p2align 4, 0x90
136 ; CHECK-NEXT: .LBB1_9: # %shared_loop_header
137 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
138 ; CHECK-NEXT: testq %rbx, %rbx
139 ; CHECK-NEXT: jne .LBB1_27
140 ; CHECK-NEXT: # %bb.10: # %inner_loop_body
141 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
142 ; CHECK-NEXT: testl %eax, %eax
143 ; CHECK-NEXT: jns .LBB1_9
144 ; CHECK-NEXT: # %bb.11: # %if.end96.i
145 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
146 ; CHECK-NEXT: cmpl $3, %ebp
147 ; CHECK-NEXT: jae .LBB1_22
148 ; CHECK-NEXT: # %bb.12: # %if.end287.i
149 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
150 ; CHECK-NEXT: xorl %esi, %esi
151 ; CHECK-NEXT: cmpl $1, %ebp
152 ; CHECK-NEXT: setne %dl
153 ; CHECK-NEXT: testb %al, %al
154 ; CHECK-NEXT: jne .LBB1_16
155 ; CHECK-NEXT: # %bb.13: # %if.end308.i
156 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
157 ; CHECK-NEXT: testb %al, %al
158 ; CHECK-NEXT: je .LBB1_7
159 ; CHECK-NEXT: # %bb.14: # %if.end335.i
160 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
161 ; CHECK-NEXT: xorl %edx, %edx
162 ; CHECK-NEXT: testb %dl, %dl
163 ; CHECK-NEXT: movl $0, %esi
164 ; CHECK-NEXT: jne .LBB1_8
165 ; CHECK-NEXT: # %bb.15: # %merge_other
166 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
167 ; CHECK-NEXT: xorl %esi, %esi
168 ; CHECK-NEXT: jmp .LBB1_17
169 ; CHECK-NEXT: .LBB1_16: # in Loop: Header=BB1_9 Depth=1
170 ; CHECK-NEXT: movb %dl, %sil
171 ; CHECK-NEXT: addl $3, %esi
172 ; CHECK-NEXT: .LBB1_17: # %outer_loop_latch
173 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
174 ; CHECK-NEXT: # implicit-def: $dl
175 ; CHECK-NEXT: jmp .LBB1_8
176 ; CHECK-NEXT: .LBB1_7: # %merge_predecessor_split
177 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
178 ; CHECK-NEXT: movb $32, %dl
179 ; CHECK-NEXT: xorl %esi, %esi
180 ; CHECK-NEXT: .LBB1_8: # %outer_loop_latch
181 ; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1
182 ; CHECK-NEXT: movzwl %si, %esi
183 ; CHECK-NEXT: decl %esi
184 ; CHECK-NEXT: movzwl %si, %esi
185 ; CHECK-NEXT: leaq 1(%rcx,%rsi), %rcx
186 ; CHECK-NEXT: testl %ebp, %ebp
187 ; CHECK-NEXT: jne .LBB1_9
188 ; CHECK-NEXT: .LBB1_18: # %while.cond.us1412.i
189 ; CHECK-NEXT: xorl %eax, %eax
190 ; CHECK-NEXT: testb %al, %al
191 ; CHECK-NEXT: movl $1, %ebx
192 ; CHECK-NEXT: jne .LBB1_20
193 ; CHECK-NEXT: # %bb.19: # %while.cond.us1412.i
194 ; CHECK-NEXT: decb %dl
195 ; CHECK-NEXT: jne .LBB1_26
196 ; CHECK-NEXT: .LBB1_20: # %if.end41.us1436.i
197 ; CHECK-NEXT: .LBB1_25:
198 ; CHECK-NEXT: movl $1, %ebx
199 ; CHECK-NEXT: jmp .LBB1_26
200 ; CHECK-NEXT: .LBB1_22: # %if.then99.i
201 ; CHECK-NEXT: xorl %ebx, %ebx
202 ; CHECK-NEXT: movl $.str.6, %edi
203 ; CHECK-NEXT: xorl %eax, %eax
204 ; CHECK-NEXT: callq cli_dbgmsg
205 ; CHECK-NEXT: .LBB1_26: # %cleanup
206 ; CHECK-NEXT: movl %ebx, %eax
207 ; CHECK-NEXT: addq $8, %rsp
208 ; CHECK-NEXT: popq %rbx
209 ; CHECK-NEXT: popq %r12
210 ; CHECK-NEXT: popq %r13
211 ; CHECK-NEXT: popq %r14
212 ; CHECK-NEXT: popq %r15
213 ; CHECK-NEXT: popq %rbp
215 ; CHECK-NEXT: .LBB1_27: # %wunpsect.exit.thread.loopexit389
216 ; CHECK-NEXT: .LBB1_28: # %wunpsect.exit.thread.loopexit391
218 %0 = load i32, i32* undef, align 4
219 %mul = shl nsw i32 %0, 2
220 br i1 undef, label %if.end19, label %cleanup
222 if.end19: ; preds = %entry
223 %conv = zext i32 %mul to i64
224 %call = tail call i8* @cli_calloc(i64 %conv, i64 1)
225 %1 = icmp eq i32 %exesz, 0
226 %notrhs = icmp eq i32 %0, 0
227 %or.cond117.not = or i1 %1, %notrhs
228 %or.cond202 = or i1 %or.cond117.not, undef
229 %cmp35 = icmp ult i8* %call, %exe
230 %or.cond203 = or i1 %or.cond202, %cmp35
231 br i1 %or.cond203, label %cleanup, label %if.end50
233 if.end50: ; preds = %if.end19
234 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i1 false)
235 %cmp1.i.i = icmp ugt i32 %mul, 3
236 br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391
238 shared_preheader: ; preds = %if.end50
239 br label %outer_loop_header
241 outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader
242 %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ]
243 %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ]
244 %2 = icmp eq i32 %0, 0
245 br i1 %2, label %while.cond.us1412.i, label %shared_loop_header
247 while.cond.us1412.i: ; preds = %outer_loop_header
248 %.pre.i = add i8 %bits.1.i, -1
249 %tobool2.us1420.i = icmp eq i8 %.pre.i, 0
250 %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i
251 br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup
253 if.end41.us1436.i: ; preds = %while.cond.us1412.i
256 shared_loop_header: ; preds = %dup_early2, %dup_early1
257 %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ]
258 %cmp3.i1172.i = icmp ult i8* null, %call
259 br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body
261 inner_loop_body: ; preds = %shared_loop_header
262 %3 = icmp slt i32 undef, 0
263 br i1 %3, label %if.end96.i, label %shared_loop_header
265 dead_block: ; preds = %inner_loop_body
266 %cmp75.i = icmp ult i8* %dst.0.i, null
267 br label %shared_loop_header
269 if.end96.i: ; preds = %inner_loop_body
270 %cmp97.i = icmp ugt i32 %0, 2
271 br i1 %cmp97.i, label %if.then99.i, label %if.end287.i
273 if.then99.i: ; preds = %if.end96.i
274 tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef)
277 if.end287.i: ; preds = %if.end96.i
278 %cmp291.i = icmp ne i32 %0, 1
279 %conv294.i = select i1 %cmp291.i, i16 4, i16 3
280 br i1 undef, label %if.end308.i, label %outer_loop_latch
282 if.end308.i: ; preds = %if.end287.i
283 br i1 undef, label %if.end335.i, label %merge_predecessor_split
285 merge_predecessor_split: ; preds = %if.end308.i
286 %4 = bitcast i8* undef to i32*
287 br label %outer_loop_latch
289 if.end335.i: ; preds = %if.end308.i
290 br i1 undef, label %outer_loop_latch, label %merge_other
292 merge_other: ; preds = %if.end335.i
293 br label %outer_loop_latch
295 outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i
296 %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ]
297 %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ]
298 %5 = add i16 %backsize.0.i, -1
299 %6 = zext i16 %5 to i64
300 %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1
301 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6
302 br label %outer_loop_header
304 wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header
307 wunpsect.exit.thread.loopexit391: ; preds = %if.end50
310 cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry
311 %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ]
315 ; Function Attrs: nounwind
316 declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0
318 ; Function Attrs: nounwind
319 declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0
321 ; Function Attrs: argmemonly nounwind
322 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
323 attributes #0 = { nounwind }
324 attributes #1 = { argmemonly nounwind }