1 ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 ; Make sure that we can handle multiple integer induction variables.
6 ; CHECK-LABEL: @multi_int_induction(
8 ; CHECK: %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
9 ; CHECK: %[[VAR:.*]] = trunc i64 %index to i32
10 ; CHECK: %offset.idx = add i32 190, %[[VAR]]
11 define void @multi_int_induction(i32* %A, i32 %N) {
16 %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
17 %count.09 = phi i32 [ 190, %for.body.lr.ph ], [ %inc, %for.body ]
18 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
19 store i32 %count.09, i32* %arrayidx2, align 4
20 %inc = add nsw i32 %count.09, 1
21 %indvars.iv.next = add i64 %indvars.iv, 1
22 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
23 %exitcond = icmp ne i32 %lftr.wideiv, %N
24 br i1 %exitcond, label %for.body, label %for.end
30 ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -instcombine -S | FileCheck %s --check-prefix=IND
32 ; Make sure we remove unneeded vectorization of induction variables.
33 ; In order for instcombine to cleanup the vectorized induction variables that we
34 ; create in the loop vectorizer we need to perform some form of redundancy
35 ; elimination to get rid of multiple uses.
37 ; IND-LABEL: scalar_use
39 ; IND: br label %vector.body
41 ; Vectorized induction variable.
42 ; IND-NOT: insertelement <2 x i64>
43 ; IND-NOT: shufflevector <2 x i64>
44 ; IND: br {{.*}}, label %vector.body
46 define void @scalar_use(float* %a, float %b, i64 %offset, i64 %offset2, i64 %n) {
51 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
52 %ind.sum = add i64 %iv, %offset
53 %arr.idx = getelementptr inbounds float, float* %a, i64 %ind.sum
54 %l1 = load float, float* %arr.idx, align 4
55 %ind.sum2 = add i64 %iv, %offset2
56 %arr.idx2 = getelementptr inbounds float, float* %a, i64 %ind.sum2
57 %l2 = load float, float* %arr.idx2, align 4
58 %m = fmul fast float %b, %l2
59 %ad = fadd fast float %l1, %m
60 store float %ad, float* %arr.idx, align 4
61 %iv.next = add nuw nsw i64 %iv, 1
62 %exitcond = icmp eq i64 %iv.next, %n
63 br i1 %exitcond, label %loopexit, label %for.body
70 ; Make sure that the loop exit count computation does not overflow for i8 and
71 ; i16. The exit count of these loops is i8/i16 max + 1. If we don't cast the
72 ; induction variable to a bigger type the exit count computation will overflow
76 ; CHECK-LABEL: i8_loop
77 ; CHECK: icmp eq i32 {{.*}}, 256
78 define i32 @i8_loop() nounwind readnone ssp uwtable {
81 ; <label>:1 ; preds = %1, %0
82 %a.0 = phi i32 [ 1, %0 ], [ %2, %1 ]
83 %b.0 = phi i8 [ 0, %0 ], [ %3, %1 ]
87 br i1 %4, label %5, label %1
89 ; <label>:5 ; preds = %1
93 ; CHECK-LABEL: i16_loop
94 ; CHECK: icmp eq i32 {{.*}}, 65536
96 define i32 @i16_loop() nounwind readnone ssp uwtable {
99 ; <label>:1 ; preds = %1, %0
100 %a.0 = phi i32 [ 1, %0 ], [ %2, %1 ]
101 %b.0 = phi i16 [ 0, %0 ], [ %3, %1 ]
103 %3 = add i16 %b.0, -1
104 %4 = icmp eq i16 %3, 0
105 br i1 %4, label %5, label %1
107 ; <label>:5 ; preds = %1
111 ; This loop has a backedge taken count of i32_max. We need to check for this
112 ; condition and branch directly to the scalar loop.
114 ; CHECK-LABEL: max_i32_backedgetaken
115 ; CHECK: %min.iters.check = icmp ult i32 0, 2
116 ; CHECK: br i1 %min.iters.check, label %scalar.ph, label %min.iters.checked
119 ; CHECK: %bc.resume.val = phi i32 [ %resume.val, %middle.block ], [ 0, %0 ]
120 ; CHECK: %bc.merge.rdx = phi i32 [ 1, %0 ], [ %5, %middle.block ]
122 define i32 @max_i32_backedgetaken() nounwind readnone ssp uwtable {
126 ; <label>:1 ; preds = %1, %0
127 %a.0 = phi i32 [ 1, %0 ], [ %2, %1 ]
128 %b.0 = phi i32 [ 0, %0 ], [ %3, %1 ]
130 %3 = add i32 %b.0, -1
131 %4 = icmp eq i32 %3, 0
132 br i1 %4, label %5, label %1
134 ; <label>:5 ; preds = %1
138 ; When generating the overflow check we must sure that the induction start value
139 ; is defined before the branch to the scalar preheader.
141 ; CHECK-LABEL: testoverflowcheck
143 ; CHECK: %[[LOAD:.*]] = load i8
147 ; CHECK: phi i8 [ %{{.*}}, %middle.block ], [ %[[LOAD]], %entry ]
149 @e = global i8 1, align 1
150 @d = common global i32 0, align 4
151 @c = common global i32 0, align 4
152 define i32 @testoverflowcheck() {
154 %.pr.i = load i8, i8* @e, align 1
155 %0 = load i32, i32* @d, align 4
156 %c.promoted.i = load i32, i32* @c, align 4
160 %inc4.i = phi i8 [ %.pr.i, %entry ], [ %inc.i, %cond.end.i ]
161 %and3.i = phi i32 [ %c.promoted.i, %entry ], [ %and.i, %cond.end.i ]
162 %and.i = and i32 %0, %and3.i
163 %inc.i = add i8 %inc4.i, 1
164 %tobool.i = icmp eq i8 %inc.i, 0
165 br i1 %tobool.i, label %loopexit, label %cond.end.i