1; RUN: opt < %s -basicaa -slp-vectorizer -dce -S -mtriple=i386-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
2
3target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128"
4target triple = "i386-apple-macosx10.9.0"
5
6;int foo(int *A, int n, int k) {
7;  for (int i=0; i < 10000; i+=4) {
8;    A[i]   += n;
9;    A[i+1] += k;
10;    A[i+2] += n;
11;    A[i+3] += k;
12;  }
13;}
14
15; preheader:
16;CHECK: entry
17;CHECK-NEXT: insertelement
18;CHECK-NEXT: insertelement
19;CHECK-NEXT: insertelement
20;CHECK-NEXT: insertelement
21; loop body:
22;CHECK: phi
23;CHECK: load <4 x i32>
24;CHECK: add nsw <4 x i32>
25;CHECK: store <4 x i32>
26;CHECK: ret
27define i32 @foo(i32* nocapture %A, i32 %n, i32 %k) {
28entry:
29  br label %for.body
30
31for.body:                                         ; preds = %entry, %for.body
32  %i.024 = phi i32 [ 0, %entry ], [ %add10, %for.body ]
33  %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.024
34  %0 = load i32, i32* %arrayidx, align 4
35  %add = add nsw i32 %0, %n
36  store i32 %add, i32* %arrayidx, align 4
37  %add121 = or i32 %i.024, 1
38  %arrayidx2 = getelementptr inbounds i32, i32* %A, i32 %add121
39  %1 = load i32, i32* %arrayidx2, align 4
40  %add3 = add nsw i32 %1, %k
41  store i32 %add3, i32* %arrayidx2, align 4
42  %add422 = or i32 %i.024, 2
43  %arrayidx5 = getelementptr inbounds i32, i32* %A, i32 %add422
44  %2 = load i32, i32* %arrayidx5, align 4
45  %add6 = add nsw i32 %2, %n
46  store i32 %add6, i32* %arrayidx5, align 4
47  %add723 = or i32 %i.024, 3
48  %arrayidx8 = getelementptr inbounds i32, i32* %A, i32 %add723
49  %3 = load i32, i32* %arrayidx8, align 4
50  %add9 = add nsw i32 %3, %k
51  store i32 %add9, i32* %arrayidx8, align 4
52  %add10 = add nsw i32 %i.024, 4
53  %cmp = icmp slt i32 %add10, 10000
54  br i1 %cmp, label %for.body, label %for.end
55
56for.end:                                          ; preds = %for.body
57  ret i32 undef
58}
59
60