2 ; RUN: opt < %s -passes=loop-vectorize,instcombine -force-vector-width=4 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output -print-after=instcombine 2>&1 | FileCheck %s
4 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
6 ; CHECK-LABEL: more_than_one_use
8 ; PR30627. Check that a compare instruction with more than one use is not
9 ; recognized as uniform and is vectorized.
11 ; CHECK-NOT: Found uniform instruction: %cond = icmp slt i64 %i.next, %n
13 ; CHECK: %[[I:.+]] = add nuw nsw <4 x i64> %vec.ind, splat (i64 1)
14 ; CHECK: icmp slt <4 x i64> %[[I]], %broadcast.splat
15 ; CHECK: br i1 {{.*}}, label %middle.block, label %vector.body
17 define i32 @more_than_one_use(ptr %a, i64 %n) {
22 %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
23 %r = phi i32 [ %tmp3, %for.body ], [ 0, %entry ]
24 %i.next = add nuw nsw i64 %i, 1
25 %cond = icmp slt i64 %i.next, %n
26 %tmp0 = select i1 %cond, i64 %i.next, i64 0
27 %tmp1 = getelementptr inbounds i32, ptr %a, i64 %tmp0
28 %tmp2 = load i32, ptr %tmp1, align 8
29 %tmp3 = add i32 %r, %tmp2
30 br i1 %cond, label %for.body, label %for.end
33 %tmp4 = phi i32 [ %tmp3, %for.body ]
37 ; Check for crash exposed by D76992.
39 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
40 ; CHECK-NEXT: Live-in vp<[[VF:%.+]]> = VF
41 ; CHECK-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
42 ; CHECK-NEXT: Live-in vp<[[VEC_TC:%.+]]> = vector-trip-count
43 ; CHECK-NEXT: Live-in vp<[[BTC:%.+]]> = backedge-taken count
44 ; CHECK-NEXT: Live-in ir<14> = original trip-count
46 ; CHECK-NEXT: vector.ph:
47 ; CHECK-NEXT: Successor(s): vector loop
49 ; CHECK-NEXT: <x1> vector loop: {
50 ; CHECK-NEXT: vector.body:
51 ; CHECK-NEXT: EMIT vp<[[CAN_IV:%.+]]> = CANONICAL-INDUCTION
52 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next, ir<1>, vp<[[VF]]
53 ; CHECK-NEXT: EMIT vp<[[COND:%.+]]> = icmp ule ir<%iv>, vp<[[BTC]]>
54 ; CHECK-NEXT: WIDEN ir<%cond0> = icmp ult ir<%iv>, ir<13>
55 ; CHECK-NEXT: WIDEN-SELECT ir<%s> = select ir<%cond0>, ir<10>, ir<20>
56 ; CHECK-NEXT: Successor(s): pred.store
58 ; CHECK-NEXT: <xVFxUF> pred.store: {
59 ; CHECK-NEXT: pred.store.entry:
60 ; CHECK-NEXT: BRANCH-ON-MASK vp<[[COND]]>
61 ; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
63 ; CHECK-NEXT: pred.store.if:
64 ; CHECK-NEXT: vp<[[STEPS:%.+]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<1>
65 ; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr inbounds ir<%ptr>, vp<[[STEPS]]>
66 ; CHECK-NEXT: REPLICATE store ir<%s>, ir<%gep>
67 ; CHECK-NEXT: Successor(s): pred.store.continue
69 ; CHECK-NEXT: pred.store.continue:
70 ; CHECK-NEXT: No successors
72 ; CHECK-NEXT: Successor(s): loop.0
75 ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT:%.+]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]>
76 ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VEC_TC]]>
77 ; CHECK-NEXT: No successor
79 define void @test(ptr %ptr) {
83 loop: ; preds = %loop, %entry
84 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
85 %cond0 = icmp ult i64 %iv, 13
86 %s = select i1 %cond0, i32 10, i32 20
87 %gep = getelementptr inbounds i32, ptr %ptr, i64 %iv
88 store i32 %s, ptr %gep
89 %iv.next = add nuw nsw i64 %iv, 1
90 %exitcond = icmp eq i64 %iv.next, 14
91 br i1 %exitcond, label %exit, label %loop