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, ptr %b, ptr %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 ptr [ %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 ptr [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ]
45 %var = load i8, ptr %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, ptr %dst.0.i, i64 1
54 %scevgep679.i = getelementptr i8, ptr %scevgep.i, i64 0
55 br label %outer_loop_top
57 inner_loop_latch: ; preds = %inner_loop_test
58 %cmp75.i = icmp ult ptr %dst.0.i, %c
59 %inc = getelementptr i8, ptr %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(ptr %exe, i32 %exesz, i32 %headsize, i32 %min, i32 %wwprva, i32 %e_lfanew, ptr 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 %r12
95 ; CHECK-NEXT: pushq %rbx
96 ; CHECK-NEXT: movl $1, %ebx
97 ; CHECK-NEXT: xorl %eax, %eax
98 ; CHECK-NEXT: testb %al, %al
99 ; CHECK-NEXT: jne .LBB1_12
100 ; CHECK-NEXT: # %bb.1: # %if.end19
101 ; CHECK-NEXT: movl (%rax), %r12d
102 ; CHECK-NEXT: leal (,%r12,4), %ebp
103 ; CHECK-NEXT: movl %ebp, %r15d
104 ; CHECK-NEXT: movl $1, %esi
105 ; CHECK-NEXT: movq %r15, %rdi
106 ; CHECK-NEXT: callq cli_calloc@PLT
107 ; CHECK-NEXT: movq %rax, %r14
108 ; CHECK-NEXT: movb $1, %al
109 ; CHECK-NEXT: testb %al, %al
110 ; CHECK-NEXT: jne .LBB1_12
111 ; CHECK-NEXT: # %bb.2: # %if.end50
112 ; CHECK-NEXT: movq %r14, %rdi
113 ; CHECK-NEXT: movq %r15, %rdx
114 ; CHECK-NEXT: callq memcpy@PLT
115 ; CHECK-NEXT: cmpl $4, %ebp
116 ; CHECK-NEXT: jb .LBB1_19
117 ; CHECK-NEXT: # %bb.3: # %shared_preheader
118 ; CHECK-NEXT: movb $32, %cl
119 ; CHECK-NEXT: xorl %eax, %eax
120 ; CHECK-NEXT: jmp .LBB1_4
121 ; CHECK-NEXT: .p2align 4, 0x90
122 ; CHECK-NEXT: .LBB1_15: # %merge_predecessor_split
123 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
124 ; CHECK-NEXT: movb $32, %cl
125 ; CHECK-NEXT: .LBB1_4: # %outer_loop_header
126 ; CHECK-NEXT: # =>This Loop Header: Depth=1
127 ; CHECK-NEXT: # Child Loop BB1_8 Depth 2
128 ; CHECK-NEXT: testl %r12d, %r12d
129 ; CHECK-NEXT: je .LBB1_5
130 ; CHECK-NEXT: .p2align 4, 0x90
131 ; CHECK-NEXT: .LBB1_8: # %shared_loop_header
132 ; CHECK-NEXT: # Parent Loop BB1_4 Depth=1
133 ; CHECK-NEXT: # => This Inner Loop Header: Depth=2
134 ; CHECK-NEXT: testq %r14, %r14
135 ; CHECK-NEXT: jne .LBB1_18
136 ; CHECK-NEXT: # %bb.9: # %inner_loop_body
137 ; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=2
138 ; CHECK-NEXT: testb %al, %al
139 ; CHECK-NEXT: je .LBB1_8
140 ; CHECK-NEXT: # %bb.10: # %if.end96.i
141 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
142 ; CHECK-NEXT: cmpl $3, %r12d
143 ; CHECK-NEXT: jae .LBB1_11
144 ; CHECK-NEXT: # %bb.13: # %if.end287.i
145 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
146 ; CHECK-NEXT: testb %al, %al
147 ; CHECK-NEXT: # implicit-def: $cl
148 ; CHECK-NEXT: jne .LBB1_4
149 ; CHECK-NEXT: # %bb.14: # %if.end308.i
150 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
151 ; CHECK-NEXT: testb %al, %al
152 ; CHECK-NEXT: je .LBB1_15
153 ; CHECK-NEXT: # %bb.16: # %if.end335.i
154 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
155 ; CHECK-NEXT: xorl %ecx, %ecx
156 ; CHECK-NEXT: testb %cl, %cl
157 ; CHECK-NEXT: jne .LBB1_4
158 ; CHECK-NEXT: # %bb.17: # %merge_other
159 ; CHECK-NEXT: # in Loop: Header=BB1_4 Depth=1
160 ; CHECK-NEXT: # implicit-def: $cl
161 ; CHECK-NEXT: jmp .LBB1_4
162 ; CHECK-NEXT: .LBB1_5: # %while.cond.us1412.i
163 ; CHECK-NEXT: xorl %eax, %eax
164 ; CHECK-NEXT: testb %al, %al
165 ; CHECK-NEXT: jne .LBB1_7
166 ; CHECK-NEXT: # %bb.6: # %while.cond.us1412.i
167 ; CHECK-NEXT: decb %cl
168 ; CHECK-NEXT: jne .LBB1_12
169 ; CHECK-NEXT: .LBB1_7: # %if.end41.us1436.i
170 ; CHECK-NEXT: .LBB1_11: # %if.then99.i
171 ; CHECK-NEXT: movq .str.6@GOTPCREL(%rip), %rdi
172 ; CHECK-NEXT: xorl %ebx, %ebx
173 ; CHECK-NEXT: xorl %eax, %eax
174 ; CHECK-NEXT: callq cli_dbgmsg@PLT
175 ; CHECK-NEXT: .LBB1_12: # %cleanup
176 ; CHECK-NEXT: movl %ebx, %eax
177 ; CHECK-NEXT: popq %rbx
178 ; CHECK-NEXT: popq %r12
179 ; CHECK-NEXT: popq %r14
180 ; CHECK-NEXT: popq %r15
181 ; CHECK-NEXT: popq %rbp
183 ; CHECK-NEXT: .LBB1_18: # %wunpsect.exit.thread.loopexit389
184 ; CHECK-NEXT: .LBB1_19: # %wunpsect.exit.thread.loopexit391
186 %0 = load i32, ptr undef, align 4
187 %mul = shl nsw i32 %0, 2
188 br i1 undef, label %if.end19, label %cleanup
190 if.end19: ; preds = %entry
191 %conv = zext i32 %mul to i64
192 %call = tail call ptr @cli_calloc(i64 %conv, i64 1)
193 %1 = icmp eq i32 %exesz, 0
194 %notrhs = icmp eq i32 %0, 0
195 %or.cond117.not = or i1 %1, %notrhs
196 %or.cond202 = or i1 %or.cond117.not, undef
197 %cmp35 = icmp ult ptr %call, %exe
198 %or.cond203 = or i1 %or.cond202, %cmp35
199 br i1 %or.cond203, label %cleanup, label %if.end50
201 if.end50: ; preds = %if.end19
202 tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull %call, ptr undef, i64 %conv, i1 false)
203 %cmp1.i.i = icmp ugt i32 %mul, 3
204 br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391
206 shared_preheader: ; preds = %if.end50
207 br label %outer_loop_header
209 outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader
210 %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ]
211 %dst.0.ph.i = phi ptr [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ]
212 %2 = icmp eq i32 %0, 0
213 br i1 %2, label %while.cond.us1412.i, label %shared_loop_header
215 while.cond.us1412.i: ; preds = %outer_loop_header
216 %.pre.i = add i8 %bits.1.i, -1
217 %tobool2.us1420.i = icmp eq i8 %.pre.i, 0
218 %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i
219 br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup
221 if.end41.us1436.i: ; preds = %while.cond.us1412.i
224 shared_loop_header: ; preds = %dup_early2, %dup_early1
225 %dst.0.i = phi ptr [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ]
226 %cmp3.i1172.i = icmp ult ptr null, %call
227 br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body
229 inner_loop_body: ; preds = %shared_loop_header
230 %3 = icmp slt i32 undef, 0
231 br i1 %3, label %if.end96.i, label %shared_loop_header
233 dead_block: ; preds = %inner_loop_body
234 %cmp75.i = icmp ult ptr %dst.0.i, null
235 br label %shared_loop_header
237 if.end96.i: ; preds = %inner_loop_body
238 %cmp97.i = icmp ugt i32 %0, 2
239 br i1 %cmp97.i, label %if.then99.i, label %if.end287.i
241 if.then99.i: ; preds = %if.end96.i
242 tail call void (ptr, ...) @cli_dbgmsg(ptr @.str.6, i32 undef)
245 if.end287.i: ; preds = %if.end96.i
246 %cmp291.i = icmp ne i32 %0, 1
247 %conv294.i = select i1 %cmp291.i, i16 4, i16 3
248 br i1 undef, label %if.end308.i, label %outer_loop_latch
250 if.end308.i: ; preds = %if.end287.i
251 br i1 undef, label %if.end335.i, label %merge_predecessor_split
253 merge_predecessor_split: ; preds = %if.end308.i
254 %4 = bitcast ptr undef to ptr
255 br label %outer_loop_latch
257 if.end335.i: ; preds = %if.end308.i
258 br i1 undef, label %outer_loop_latch, label %merge_other
260 merge_other: ; preds = %if.end335.i
261 br label %outer_loop_latch
263 outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i
264 %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ]
265 %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ]
266 %5 = add i16 %backsize.0.i, -1
267 %6 = zext i16 %5 to i64
268 %scevgep.i = getelementptr i8, ptr %dst.0.ph.i, i64 1
269 %scevgep679.i = getelementptr i8, ptr %scevgep.i, i64 %6
270 br label %outer_loop_header
272 wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header
275 wunpsect.exit.thread.loopexit391: ; preds = %if.end50
278 cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry
279 %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ]
283 ; Function Attrs: nounwind
284 declare void @cli_dbgmsg(ptr, ...) local_unnamed_addr #0
286 ; Function Attrs: nounwind
287 declare ptr @cli_calloc(i64, i64) local_unnamed_addr #0
289 ; Function Attrs: argmemonly nounwind
290 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1) #1
291 attributes #0 = { nounwind }
292 attributes #1 = { argmemonly nounwind }