1*cee313d2SEric Christopher; RUN: opt < %s  -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S | FileCheck %s
2*cee313d2SEric Christopher
3*cee313d2SEric Christophertarget 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"
4*cee313d2SEric Christopher
5*cee313d2SEric Christopher@a = common global [2048 x i32] zeroinitializer, align 16
6*cee313d2SEric Christopher
7*cee313d2SEric Christopher; This is the loop.
8*cee313d2SEric Christopher;  for (i=0; i<n; i++){
9*cee313d2SEric Christopher;    a[i] += i;
10*cee313d2SEric Christopher;  }
11*cee313d2SEric Christopher;CHECK-LABEL: @inc(
12*cee313d2SEric Christopher;CHECK: load <4 x i32>
13*cee313d2SEric Christopher;CHECK: add nsw <4 x i32>
14*cee313d2SEric Christopher;CHECK: store <4 x i32>
15*cee313d2SEric Christopher;CHECK: ret void
16*cee313d2SEric Christopherdefine void @inc(i32 %n) nounwind uwtable noinline ssp {
17*cee313d2SEric Christopher  %1 = icmp sgt i32 %n, 0
18*cee313d2SEric Christopher  br i1 %1, label %.lr.ph, label %._crit_edge
19*cee313d2SEric Christopher
20*cee313d2SEric Christopher.lr.ph:                                           ; preds = %0, %.lr.ph
21*cee313d2SEric Christopher  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
22*cee313d2SEric Christopher  %2 = getelementptr inbounds [2048 x i32], [2048 x i32]* @a, i64 0, i64 %indvars.iv
23*cee313d2SEric Christopher  %3 = load i32, i32* %2, align 4
24*cee313d2SEric Christopher  %4 = trunc i64 %indvars.iv to i32
25*cee313d2SEric Christopher  %5 = add nsw i32 %3, %4
26*cee313d2SEric Christopher  store i32 %5, i32* %2, align 4
27*cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
28*cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
29*cee313d2SEric Christopher  %exitcond = icmp eq i32 %lftr.wideiv, %n
30*cee313d2SEric Christopher  br i1 %exitcond, label %._crit_edge, label %.lr.ph
31*cee313d2SEric Christopher
32*cee313d2SEric Christopher._crit_edge:                                      ; preds = %.lr.ph, %0
33*cee313d2SEric Christopher  ret void
34*cee313d2SEric Christopher}
35*cee313d2SEric Christopher
36*cee313d2SEric Christopher; Can't vectorize this loop because the access to A[X] is non-linear.
37*cee313d2SEric Christopher;
38*cee313d2SEric Christopher;  for (i = 0; i < n; ++i) {
39*cee313d2SEric Christopher;    A[B[i]]++;
40*cee313d2SEric Christopher;
41*cee313d2SEric Christopher;CHECK-LABEL: @histogram(
42*cee313d2SEric Christopher;CHECK-NOT: <4 x i32>
43*cee313d2SEric Christopher;CHECK: ret i32
44*cee313d2SEric Christopherdefine i32 @histogram(i32* nocapture noalias %A, i32* nocapture noalias %B, i32 %n) nounwind uwtable ssp {
45*cee313d2SEric Christopherentry:
46*cee313d2SEric Christopher  %cmp6 = icmp sgt i32 %n, 0
47*cee313d2SEric Christopher  br i1 %cmp6, label %for.body, label %for.end
48*cee313d2SEric Christopher
49*cee313d2SEric Christopherfor.body:                                         ; preds = %entry, %for.body
50*cee313d2SEric Christopher  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
51*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
52*cee313d2SEric Christopher  %0 = load i32, i32* %arrayidx, align 4
53*cee313d2SEric Christopher  %idxprom1 = sext i32 %0 to i64
54*cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %idxprom1
55*cee313d2SEric Christopher  %1 = load i32, i32* %arrayidx2, align 4
56*cee313d2SEric Christopher  %inc = add nsw i32 %1, 1
57*cee313d2SEric Christopher  store i32 %inc, i32* %arrayidx2, align 4
58*cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
59*cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
60*cee313d2SEric Christopher  %exitcond = icmp eq i32 %lftr.wideiv, %n
61*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
62*cee313d2SEric Christopher
63*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body, %entry
64*cee313d2SEric Christopher  ret i32 0
65*cee313d2SEric Christopher}
66