2 ; RUN: opt < %s -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -force-widen-divrem-via-safe-divisor=0 -disable-output -debug-only=loop-vectorize 2>&1 | FileCheck %s
4 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
6 ; Test cases for PR50009, which require sinking a replicate-region due to a
7 ; first-order recurrence.
9 define void @sink_replicate_region_1(i32 %x, ptr %ptr, ptr noalias %dst) optsize {
10 ; CHECK-LABEL: sink_replicate_region_1
11 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
12 ; CHECK-NEXT: Live-in vp<[[VF:%.+]]> = VF
13 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
14 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
15 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
16 ; CHECK-NEXT: Live-in ir<20001> = original trip-count
18 ; CHECK-NEXT: vector.ph:
19 ; CHECK-NEXT: Successor(s): vector loop
21 ; CHECK-NEXT: <x1> vector loop: {
22 ; CHECK-NEXT: vector.body:
23 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
24 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%0> = phi ir<0>, ir<%conv>
25 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next, ir<1>, vp<[[VF]]>
26 ; CHECK-NEXT: vp<[[STEPS:%.]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<1>
27 ; CHECK-NEXT: EMIT vp<[[MASK:%.+]]> = icmp ule ir<%iv>, vp<[[BTC]]>
28 ; CHECK-NEXT: Successor(s): pred.load
30 ; CHECK-NEXT: <xVFxUF> pred.load: {
31 ; CHECK-NEXT: pred.load.entry:
32 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
33 ; CHECK-NEXT: Successor(s): pred.load.if, pred.load.continue
35 ; CHECK-NEXT: pred.load.if:
36 ; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEPS]]>
37 ; CHECK-NEXT: REPLICATE ir<%lv> = load ir<%gep> (S->V)
38 ; CHECK-NEXT: Successor(s): pred.load.continue
40 ; CHECK-NEXT: pred.load.continue:
41 ; CHECK-NEXT: PHI-PREDICATED-INSTRUCTION vp<[[PRED1:%.+]]> = ir<%lv>
42 ; CHECK-NEXT: No successors
44 ; CHECK-NEXT: Successor(s): loop.0
47 ; CHECK-NEXT: WIDEN-CAST ir<%conv> = sext vp<[[PRED1]]> to i32
48 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%0>, ir<%conv>
49 ; CHECK-NEXT: Successor(s): pred.store
51 ; CHECK-NEXT: <xVFxUF> pred.store: {
52 ; CHECK-NEXT: pred.store.entry:
53 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
54 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
56 ; CHECK-NEXT: pred.store.if:
57 ; CHECK-NEXT: REPLICATE ir<%rem> = srem vp<[[SPLICE]]>, ir<%x>
58 ; CHECK-NEXT: REPLICATE ir<%gep.dst> = getelementptr ir<%dst>, vp<[[STEPS]]>
59 ; CHECK-NEXT: REPLICATE ir<%add> = add ir<%conv>, ir<%rem>
60 ; CHECK-NEXT: REPLICATE store ir<%add>, ir<%gep.dst>
61 ; CHECK-NEXT: Successor(s): pred.store.continue
63 ; CHECK-NEXT: pred.store.continue:
64 ; CHECK-NEXT: No successors
66 ; CHECK-NEXT: Successor(s): loop.1
69 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
70 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
71 ; CHECK-NEXT: No successors
73 ; CHECK-NEXT: Successor(s): middle.block
75 ; CHECK-NEXT: middle.block:
76 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%conv>, ir<1>
77 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
78 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
80 ; CHECK-NEXT: ir-bb<exit>
81 ; CHECK-NEXT: No successors
83 ; CHECK-NEXT: scalar.ph
84 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
85 ; CHECK-NEXT: Successor(s): ir-bb<loop>
87 ; CHECK-NEXT: ir-bb<loop>:
88 ; CHECK-NEXT: IR %0 = phi i32 [ 0, %entry ], [ %conv, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
89 ; CHECK-NEXT: IR %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
90 ; CHECK: IR %ec = icmp eq i32 %iv.next, 20001
91 ; CHECK-NEXT: No successors
98 %0 = phi i32 [ 0, %entry ], [ %conv, %loop ]
99 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
100 %rem = srem i32 %0, %x
101 %gep = getelementptr i8, ptr %ptr, i32 %iv
102 %lv = load i8, ptr %gep
103 %conv = sext i8 %lv to i32
104 %add = add i32 %conv, %rem
105 %gep.dst = getelementptr i32, ptr %dst, i32 %iv
106 store i32 %add, ptr %gep.dst
107 %iv.next = add nsw i32 %iv, 1
108 %ec = icmp eq i32 %iv.next, 20001
109 br i1 %ec, label %exit, label %loop
115 define void @sink_replicate_region_2(i32 %x, i8 %y, ptr %ptr) optsize {
116 ; CHECK-LABEL: sink_replicate_region_2
117 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
118 ; CHECK-NEXT: Live-in vp<[[VF:%.+]]> = VF
119 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
120 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
121 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
122 ; CHECK-NEXT: Live-in ir<20001> = original trip-count
124 ; CHECK-NEXT: vector.ph:
125 ; CHECK-NEXT: WIDEN-CAST ir<%recur.next> = sext ir<%y> to i32
126 ; CHECK-NEXT: Successor(s): vector loop
128 ; CHECK-NEXT: <x1> vector loop: {
129 ; CHECK-NEXT: vector.body:
130 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
131 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%recur> = phi ir<0>, ir<%recur.next>
132 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next, ir<1>, vp<[[VF]]>
133 ; CHECK-NEXT: EMIT vp<[[MASK:%.+]]> = icmp ule ir<%iv>, vp<[[BTC]]>
134 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%recur>, ir<%recur.next>
135 ; CHECK-NEXT: Successor(s): pred.store
137 ; CHECK-NEXT: <xVFxUF> pred.store: {
138 ; CHECK-NEXT: pred.store.entry:
139 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
140 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
142 ; CHECK-NEXT: pred.store.if:
143 ; CHECK-NEXT: vp<[[STEPS:%.+]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<1>
144 ; CHECK-NEXT: REPLICATE ir<%rem> = srem vp<[[SPLICE]]>, ir<%x>
145 ; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEPS]]>
146 ; CHECK-NEXT: REPLICATE ir<%add> = add ir<%rem>, ir<%recur.next>
147 ; CHECK-NEXT: REPLICATE store ir<%add>, ir<%gep>
148 ; CHECK-NEXT: Successor(s): pred.store.continue
150 ; CHECK-NEXT: pred.store.continue:
151 ; CHECK-NEXT: No successors
153 ; CHECK-NEXT: Successor(s): loop.0
155 ; CHECK-NEXT: loop.0:
156 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
157 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
158 ; CHECK-NEXT: No successors
160 ; CHECK-NEXT: Successor(s): middle.block
162 ; CHECK-NEXT: middle.block:
163 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%recur.next>, ir<1>
164 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
165 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
167 ; CHECK-NEXT: ir-bb<exit>
168 ; CHECK-NEXT: No successors
170 ; CHECK-NEXT: scalar.ph
171 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
172 ; CHECK-NEXT: Successor(s): ir-bb<loop>
174 ; CHECK-NEXT: ir-bb<loop>:
175 ; CHECK-NEXT: IR %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
176 ; CHECK-NEXT: IR %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
177 ; CHECK: IR %ec = icmp eq i32 %iv.next, 20001
178 ; CHECK-NEXT: No successors
185 %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ]
186 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
187 %rem = srem i32 %recur, %x
188 %recur.next = sext i8 %y to i32
189 %add = add i32 %rem, %recur.next
190 %gep = getelementptr i32, ptr %ptr, i32 %iv
191 store i32 %add, ptr %gep
192 %iv.next = add nsw i32 %iv, 1
193 %ec = icmp eq i32 %iv.next, 20001
194 br i1 %ec, label %exit, label %loop
200 define i32 @sink_replicate_region_3_reduction(i32 %x, i8 %y, ptr %ptr) optsize {
201 ; CHECK-LABEL: sink_replicate_region_3_reduction
202 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
203 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
204 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
205 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
206 ; CHECK-NEXT: Live-in ir<20001> = original trip-count
208 ; CHECK-NEXT: vector.ph:
209 ; CHECK-NEXT: WIDEN-CAST ir<%recur.next> = sext ir<%y> to i32
210 ; CHECK-NEXT: Successor(s): vector loop
212 ; CHECK-NEXT: <x1> vector loop: {
213 ; CHECK-NEXT: vector.body:
214 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
215 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%recur> = phi ir<0>, ir<%recur.next>
216 ; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%and.red> = phi ir<1234>, ir<%and.red.next>
217 ; CHECK-NEXT: EMIT vp<[[WIDEN_CAN:%.+]]> = WIDEN-CANONICAL-INDUCTION vp<[[CAN_IV]]>
218 ; CHECK-NEXT: EMIT vp<[[MASK:%.+]]> = icmp ule vp<[[WIDEN_CAN]]>, vp<[[BTC]]>
219 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%recur>, ir<%recur.next>
220 ; CHECK-NEXT: WIDEN ir<%rem> = srem vp<[[SPLICE]]>, ir<%x>
221 ; CHECK-NEXT: WIDEN ir<%add> = add ir<%rem>, ir<%recur.next>
222 ; CHECK-NEXT: WIDEN ir<%and.red.next> = and ir<%and.red>, ir<%add>
223 ; CHECK-NEXT: EMIT vp<[[SEL:%.+]]> = select vp<[[MASK]]>, ir<%and.red.next>, ir<%and.red>
224 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
225 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
226 ; CHECK-NEXT: No successors
228 ; CHECK-NEXT: Successor(s): middle.block
230 ; CHECK-NEXT: middle.block:
231 ; CHECK-NEXT: EMIT vp<[[RED_RES:%.+]]> = compute-reduction-result ir<%and.red>, vp<[[SEL]]>
232 ; CHECK-NEXT: EMIT vp<[[RED_EX:%.+]]> = extract-from-end vp<[[RED_RES]]>, ir<1>
233 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%recur.next>, ir<1>
234 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
235 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
237 ; CHECK-NEXT: ir-bb<exit>
238 ; CHECK-NEXT: IR %res = phi i32 [ %and.red.next, %loop ] (extra operand: vp<[[RED_EX]]> from middle.block)
239 ; CHECK-NEXT: No successors
241 ; CHECK-NEXT: scalar.ph
242 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
243 ; CHECK-NEXT: EMIT vp<[[RESUME_RED:%.+]]> = resume-phi vp<[[RED_RES]]>, ir<1234>
244 ; CHECK-NEXT: Successor(s): ir-bb<loop>
246 ; CHECK-NEXT: ir-bb<loop>:
247 ; CHECK-NEXT: IR %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
248 ; CHECK-NEXT: IR %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
249 ; CHECK-NEXT: IR %and.red = phi i32 [ 1234, %entry ], [ %and.red.next, %loop ]
250 ; CHECK: IR %ec = icmp eq i32 %iv.next, 20001
251 ; CHECK-NEXT: No successors
258 %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ]
259 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
260 %and.red = phi i32 [ 1234, %entry ], [ %and.red.next, %loop ]
261 %rem = srem i32 %recur, %x
262 %recur.next = sext i8 %y to i32
263 %add = add i32 %rem, %recur.next
264 %and.red.next = and i32 %and.red, %add
265 %iv.next = add nsw i32 %iv, 1
266 %ec = icmp eq i32 %iv.next, 20001
267 br i1 %ec, label %exit, label %loop
270 %res = phi i32 [ %and.red.next, %loop ]
274 ; To sink the replicate region containing %rem, we need to split the block
275 ; containing %conv at the end, because %conv is the last recipe in the block.
276 define void @sink_replicate_region_4_requires_split_at_end_of_block(i32 %x, ptr %ptr, ptr noalias %dst) optsize {
277 ; CHECK-LABEL: sink_replicate_region_4_requires_split_at_end_of_block
278 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
279 ; CHECK-NEXT: Live-in vp<[[VF:%.+]]> = VF
280 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
281 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
282 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
283 ; CHECK-NEXT: Live-in ir<20001> = original trip-count
285 ; CHECK-NEXT: vector.ph:
286 ; CHECK-NEXT: Successor(s): vector loop
288 ; CHECK-NEXT: <x1> vector loop: {
289 ; CHECK-NEXT: vector.body:
290 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
291 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%0> = phi ir<0>, ir<%conv>
292 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next, ir<1>, vp<[[VF]]>
293 ; CHECK-NEXT: vp<[[STEPS:%.+]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<1>
294 ; CHECK-NEXT: EMIT vp<[[MASK:%.+]]> = icmp ule ir<%iv>, vp<[[BTC]]>
295 ; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEPS]]>
296 ; CHECK-NEXT: Successor(s): pred.load
298 ; CHECK-NEXT: <xVFxUF> pred.load: {
299 ; CHECK-NEXT: pred.load.entry:
300 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
301 ; CHECK-NEXT: Successor(s): pred.load.if, pred.load.continue
303 ; CHECK-NEXT: pred.load.if:
304 ; CHECK-NEXT: REPLICATE ir<%lv> = load ir<%gep> (S->V)
305 ; CHECK-NEXT: Successor(s): pred.load.continue
307 ; CHECK-NEXT: pred.load.continue:
308 ; CHECK-NEXT: PHI-PREDICATED-INSTRUCTION vp<[[PRED:%.+]]> = ir<%lv>
309 ; CHECK-NEXT: No successors
311 ; CHECK-NEXT: Successor(s): loop.0
313 ; CHECK-NEXT: loop.0:
314 ; CHECK-NEXT: WIDEN-CAST ir<%conv> = sext vp<[[PRED]]> to i32
315 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%0>, ir<%conv>
316 ; CHECK-NEXT: Successor(s): pred.store
318 ; CHECK: <xVFxUF> pred.store: {
319 ; CHECK-NEXT: pred.store.entry:
320 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
321 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
323 ; CHECK: pred.store.if:
324 ; CHECK-NEXT: REPLICATE ir<%lv.2> = load ir<%gep>
325 ; CHECK-NEXT: REPLICATE ir<%rem> = srem vp<[[SPLICE]]>, ir<%x>
326 ; CHECK-NEXT: REPLICATE ir<%conv.lv.2> = sext ir<%lv.2>
327 ; CHECK-NEXT: REPLICATE ir<%add.1> = add ir<%conv>, ir<%rem>
328 ; CHECK-NEXT: REPLICATE ir<%gep.dst> = getelementptr ir<%dst>, vp<[[STEPS]]>
329 ; CHECK-NEXT: REPLICATE ir<%add> = add ir<%add.1>, ir<%conv.lv.2>
330 ; CHECK-NEXT: REPLICATE store ir<%add>, ir<%gep.dst>
331 ; CHECK-NEXT: Successor(s): pred.store.continue
333 ; CHECK: pred.store.continue:
334 ; CHECK-NEXT: No successors
336 ; CHECK-NEXT: Successor(s): loop.2
339 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
340 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
341 ; CHECK-NEXT: No successors
343 ; CHECK-NEXT: Successor(s): middle.block
345 ; CHECK-NEXT: middle.block:
346 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%conv>, ir<1>
347 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
348 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
350 ; CHECK-NEXT: ir-bb<exit>
351 ; CHECK-NEXT: No successors
353 ; CHECK-NEXT: scalar.ph
354 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
355 ; CHECK-NEXT: Successor(s): ir-bb<loop>
357 ; CHECK-NEXT: ir-bb<loop>:
358 ; CHECK-NEXT: IR %0 = phi i32 [ 0, %entry ], [ %conv, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
359 ; CHECK-NEXT: IR %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
360 ; CHECK: IR %ec = icmp eq i32 %iv.next, 20001
361 ; CHECK-NEXT: No successors
368 %0 = phi i32 [ 0, %entry ], [ %conv, %loop ]
369 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
370 %gep = getelementptr i8, ptr %ptr, i32 %iv
371 %rem = srem i32 %0, %x
372 %lv = load i8, ptr %gep
373 %conv = sext i8 %lv to i32
374 %lv.2 = load i8, ptr %gep
375 %add.1 = add i32 %conv, %rem
376 %conv.lv.2 = sext i8 %lv.2 to i32
377 %add = add i32 %add.1, %conv.lv.2
378 %gep.dst = getelementptr i32, ptr %dst, i32 %iv
379 store i32 %add, ptr %gep.dst
380 %iv.next = add nsw i32 %iv, 1
381 %ec = icmp eq i32 %iv.next, 20001
382 br i1 %ec, label %exit, label %loop
388 ; Test case that requires sinking a recipe in a replicate region after another replicate region.
389 define void @sink_replicate_region_after_replicate_region(ptr %ptr, ptr noalias %dst.2, i32 %x, i8 %y) optsize {
390 ; CHECK-LABEL: sink_replicate_region_after_replicate_region
391 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
392 ; CHECK-NEXT: Live-in vp<[[VF:%.+]]> = VF
393 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
394 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
395 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
396 ; CHECK-NEXT: vp<[[TC:%.+]]> = original trip-count
398 ; CHECK-NEXT: ir-bb<entry>:
399 ; CHECK-NEXT: EMIT vp<[[TC]]> = EXPAND SCEV (1 smax (1 + (sext i8 %y to i32))<nsw>)
400 ; CHECK-NEXT: No successors
402 ; CHECK-NEXT: vector.ph:
403 ; CHECK-NEXT: WIDEN-CAST ir<%recur.next> = sext ir<%y> to i32
404 ; CHECK-NEXT: Successor(s): vector loop
406 ; CHECK-NEXT: <x1> vector loop: {
407 ; CHECK-NEXT: vector.body:
408 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
409 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%recur> = phi ir<0>, ir<%recur.next>
410 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next, ir<1>, vp<[[VF]]>
411 ; CHECK-NEXT: EMIT vp<[[MASK:%.+]]> = icmp ule ir<%iv>, vp<[[BTC]]>
412 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%recur>, ir<%recur.next>
413 ; CHECK-NEXT: Successor(s): pred.store
415 ; CHECK-NEXT: <xVFxUF> pred.store: {
416 ; CHECK-NEXT: pred.store.entry:
417 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[MASK]]>
418 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
420 ; CHECK-NEXT: pred.store.if:
421 ; CHECK-NEXT: vp<[[STEPS:%.+]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<1>
422 ; CHECK-NEXT: REPLICATE ir<%rem> = srem vp<[[SPLICE]]>, ir<%x>
423 ; CHECK-NEXT: REPLICATE ir<%rem.div> = sdiv ir<20>, ir<%rem>
424 ; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEPS]]>
425 ; CHECK-NEXT: REPLICATE store ir<%rem.div>, ir<%gep>
426 ; CHECK-NEXT: REPLICATE ir<%gep.2> = getelementptr ir<%dst.2>, vp<[[STEPS]]>
427 ; CHECK-NEXT: REPLICATE store ir<%rem.div>, ir<%gep.2>
428 ; CHECK-NEXT: Successor(s): pred.store.continue
430 ; CHECK-NEXT: pred.store.continue:
431 ; CHECK-NEXT: No successors
433 ; CHECK-NEXT: Successor(s): loop.2
435 ; CHECK-NEXT: loop.2:
436 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
437 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
438 ; CHECK-NEXT: No successors
440 ; CHECK-NEXT: Successor(s): middle.block
442 ; CHECK-NEXT: middle.block:
443 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%recur.next>, ir<1>
444 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
445 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
447 ; CHECK-NEXT: ir-bb<exit>
448 ; CHECK-NEXT: No successors
450 ; CHECK-NEXT: scalar.ph
451 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
452 ; CHECK-NEXT: Successor(s): ir-bb<loop>
454 ; CHECK-NEXT: ir-bb<loop>:
455 ; CHECK-NEXT: IR %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
456 ; CHECK-NEXT: IR %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
457 ; CHECK: IR %C = icmp sgt i32 %iv.next, %recur.next
458 ; CHECK-NEXT: No successors
464 loop: ; preds = %loop, %entry
465 %recur = phi i32 [ 0, %entry ], [ %recur.next, %loop ]
466 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
467 %rem = srem i32 %recur, %x
468 %rem.div = sdiv i32 20, %rem
469 %recur.next = sext i8 %y to i32
470 %gep = getelementptr i32, ptr %ptr, i32 %iv
471 store i32 %rem.div, ptr %gep
472 %gep.2 = getelementptr i32, ptr %dst.2, i32 %iv
473 store i32 %rem.div, ptr %gep.2
474 %iv.next = add nsw i32 %iv, 1
475 %C = icmp sgt i32 %iv.next, %recur.next
476 br i1 %C, label %exit, label %loop
478 exit: ; preds = %loop
482 define void @need_new_block_after_sinking_pr56146(i32 %x, ptr %src, ptr noalias %dst) {
483 ; CHECK-LABEL: need_new_block_after_sinking_pr56146
484 ; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
485 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
486 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
487 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
488 ; CHECK-NEXT: Live-in ir<3> = original trip-count
490 ; CHECK-NEXT: vector.ph:
491 ; CHECK-NEXT: Successor(s): vector loop
493 ; CHECK-NEXT: <x1> vector loop: {
494 ; CHECK-NEXT: vector.body:
495 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
496 ; CHECK-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<%.pn> = phi ir<0>, ir<[[L:%.+]]>
497 ; CHECK-NEXT: vp<[[DERIVED_IV:%.+]]> = DERIVED-IV ir<2> + vp<[[CAN_IV]]> * ir<1>
498 ; CHECK-NEXT: EMIT vp<[[WIDE_IV:%.+]]> = WIDEN-CANONICAL-INDUCTION vp<[[CAN_IV]]>
499 ; CHECK-NEXT: EMIT vp<[[CMP:%.+]]> = icmp ule vp<[[WIDE_IV]]>, vp<[[BTC]]>
500 ; CHECK-NEXT: CLONE ir<[[L]]> = load ir<%src>
501 ; CHECK-NEXT: EMIT vp<[[SPLICE:%.+]]> = first-order splice ir<%.pn>, ir<[[L]]>
502 ; CHECK-NEXT: Successor(s): pred.store
504 ; CHECK-NEXT: <xVFxUF> pred.store: {
505 ; CHECK-NEXT: pred.store.entry:
506 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[CMP]]>
507 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
509 ; CHECK-NEXT: pred.store.if:
510 ; CHECK-NEXT: vp<[[SCALAR_STEPS:%.+]]> = SCALAR-STEPS vp<[[DERIVED_IV]]>, ir<1>
511 ; CHECK-NEXT: REPLICATE ir<%gep.dst> = getelementptr ir<%dst>, vp<[[SCALAR_STEPS]]>
512 ; CHECK-NEXT: REPLICATE ir<%val> = sdiv vp<[[SPLICE]]>, ir<%x>
513 ; CHECK-NEXT: REPLICATE store ir<%val>, ir<%gep.dst>
514 ; CHECK-NEXT: Successor(s): pred.store.continue
516 ; CHECK-NEXT: pred.store.continue:
517 ; CHECK-NEXT: No successors
519 ; CHECK-NEXT: Successor(s): loop.0
521 ; CHECK-NEXT: loop.0:
522 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
523 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
524 ; CHECK-NEXT: No successors
526 ; CHECK-NEXT: Successor(s): middle.block
528 ; CHECK-NEXT: middle.block:
529 ; CHECK-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-from-end ir<%l>, ir<1>
530 ; CHECK-NEXT: EMIT branch-on-cond ir<true>
531 ; CHECK-NEXT: Successor(s): ir-bb<exit>, scalar.ph
533 ; CHECK-NEXT: ir-bb<exit>
534 ; CHECK-NEXT: No successors
536 ; CHECK-NEXT: scalar.ph
537 ; CHECK-NEXT: EMIT vp<[[RESUME_1_P:%.*]]> = resume-phi vp<[[RESUME_1]]>, ir<0>
538 ; CHECK-NEXT: Successor(s): ir-bb<loop>
540 ; CHECK-NEXT: ir-bb<loop>:
541 ; CHECK-NEXT: IR %iv = phi i64 [ 2, %entry ], [ %iv.next, %loop ]
542 ; CHECK-NEXT: IR %.pn = phi i32 [ 0, %entry ], [ %l, %loop ] (extra operand: vp<[[RESUME_1_P]]> from scalar.ph)
543 ; CHECK: IR %ec = icmp ugt i64 %iv, 3
544 ; CHECK-NEXT: No successors
551 %iv = phi i64 [ 2, %entry ], [ %iv.next, %loop ]
552 %.pn = phi i32 [ 0, %entry ], [ %l, %loop ]
553 %val = sdiv i32 %.pn, %x
554 %l = load i32, ptr %src, align 4
555 %gep.dst = getelementptr i32, ptr %dst, i64 %iv
556 store i32 %val, ptr %gep.dst
557 %iv.next = add nuw nsw i64 %iv, 1
558 %ec = icmp ugt i64 %iv, 3
559 br i1 %ec, label %exit, label %loop