Elena Demikhovsky | c434d09 | 2016-05-10 07:33:35 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=8 -S | FileCheck %s |
| 2 | |
| 3 | ; int int_inc; |
| 4 | ; |
| 5 | ;int induction_with_global(int init, int *restrict A, int N) { |
| 6 | ; int x = init; |
| 7 | ; for (int i=0;i<N;i++){ |
| 8 | ; A[i] = x; |
| 9 | ; x += int_inc; |
| 10 | ; } |
| 11 | ; return x; |
| 12 | ;} |
| 13 | |
| 14 | ; CHECK-LABEL: @induction_with_global( |
| 15 | ; CHECK: %[[INT_INC:.*]] = load i32, i32* @int_inc, align 4 |
| 16 | ; CHECK: vector.body: |
| 17 | ; CHECK: %[[VAR1:.*]] = insertelement <8 x i32> undef, i32 %[[INT_INC]], i32 0 |
| 18 | ; CHECK: %[[VAR2:.*]] = shufflevector <8 x i32> %[[VAR1]], <8 x i32> undef, <8 x i32> zeroinitializer |
| 19 | ; CHECK: mul <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, %[[VAR2]] |
| 20 | |
| 21 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 22 | |
| 23 | |
| 24 | @int_inc = common global i32 0, align 4 |
| 25 | |
| 26 | define i32 @induction_with_global(i32 %init, i32* noalias nocapture %A, i32 %N) { |
| 27 | entry: |
| 28 | %cmp4 = icmp sgt i32 %N, 0 |
| 29 | br i1 %cmp4, label %for.body.lr.ph, label %for.end |
| 30 | |
| 31 | for.body.lr.ph: ; preds = %entry |
| 32 | %0 = load i32, i32* @int_inc, align 4 |
| 33 | %1 = mul i32 %0, %N |
| 34 | br label %for.body |
| 35 | |
| 36 | for.body: ; preds = %for.body, %for.body.lr.ph |
| 37 | %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ] |
| 38 | %x.05 = phi i32 [ %init, %for.body.lr.ph ], [ %add, %for.body ] |
| 39 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 40 | store i32 %x.05, i32* %arrayidx, align 4 |
| 41 | %add = add nsw i32 %0, %x.05 |
| 42 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 43 | %lftr.wideiv = trunc i64 %indvars.iv.next to i32 |
| 44 | %exitcond = icmp eq i32 %lftr.wideiv, %N |
| 45 | br i1 %exitcond, label %for.end.loopexit, label %for.body |
| 46 | |
| 47 | for.end.loopexit: ; preds = %for.body |
| 48 | %2 = add i32 %1, %init |
| 49 | br label %for.end |
| 50 | |
| 51 | for.end: ; preds = %for.end.loopexit, %entry |
| 52 | %x.0.lcssa = phi i32 [ %init, %entry ], [ %2, %for.end.loopexit ] |
| 53 | ret i32 %x.0.lcssa |
| 54 | } |
| 55 | |
| 56 | |
| 57 | ;int induction_with_loop_inv(int init, int *restrict A, int N, int M) { |
| 58 | ; int x = init; |
| 59 | ; for (int j = 0; j < M; j++) { |
| 60 | ; for (int i=0; i<N; i++){ |
| 61 | ; A[i] = x; |
| 62 | ; x += j; // induction step is a loop invariant variable |
| 63 | ; } |
| 64 | ; } |
| 65 | ; return x; |
| 66 | ;} |
| 67 | |
| 68 | ; CHECK-LABEL: @induction_with_loop_inv( |
| 69 | ; CHECK: for.cond1.preheader: |
| 70 | ; CHECK: %[[INDVAR0:.*]] = phi i32 [ 0, |
| 71 | ; CHECK: %[[INDVAR1:.*]] = phi i32 [ 0, |
| 72 | ; CHECK: vector.body: |
| 73 | ; CHECK: %[[VAR1:.*]] = insertelement <8 x i32> undef, i32 %[[INDVAR1]], i32 0 |
| 74 | ; CHECK: %[[VAR2:.*]] = shufflevector <8 x i32> %[[VAR1]], <8 x i32> undef, <8 x i32> zeroinitializer |
| 75 | ; CHECK: mul <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, %[[VAR2]] |
| 76 | |
| 77 | define i32 @induction_with_loop_inv(i32 %init, i32* noalias nocapture %A, i32 %N, i32 %M) { |
| 78 | entry: |
| 79 | %cmp10 = icmp sgt i32 %M, 0 |
| 80 | br i1 %cmp10, label %for.cond1.preheader.lr.ph, label %for.end6 |
| 81 | |
| 82 | for.cond1.preheader.lr.ph: ; preds = %entry |
| 83 | %cmp27 = icmp sgt i32 %N, 0 |
| 84 | br label %for.cond1.preheader |
| 85 | |
| 86 | for.cond1.preheader: ; preds = %for.inc4, %for.cond1.preheader.lr.ph |
| 87 | %indvars.iv15 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next16, %for.inc4 ] |
| 88 | %j.012 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc5, %for.inc4 ] |
| 89 | %x.011 = phi i32 [ %init, %for.cond1.preheader.lr.ph ], [ %x.1.lcssa, %for.inc4 ] |
| 90 | br i1 %cmp27, label %for.body3.preheader, label %for.inc4 |
| 91 | |
| 92 | for.body3.preheader: ; preds = %for.cond1.preheader |
| 93 | br label %for.body3 |
| 94 | |
| 95 | for.body3: ; preds = %for.body3.preheader, %for.body3 |
| 96 | %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 0, %for.body3.preheader ] |
| 97 | %x.18 = phi i32 [ %add, %for.body3 ], [ %x.011, %for.body3.preheader ] |
| 98 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 99 | store i32 %x.18, i32* %arrayidx, align 4 |
| 100 | %add = add nsw i32 %x.18, %j.012 |
| 101 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 102 | %lftr.wideiv = trunc i64 %indvars.iv.next to i32 |
| 103 | %exitcond = icmp eq i32 %lftr.wideiv, %N |
| 104 | br i1 %exitcond, label %for.inc4.loopexit, label %for.body3 |
| 105 | |
| 106 | for.inc4.loopexit: ; preds = %for.body3 |
| 107 | %0 = add i32 %x.011, %indvars.iv15 |
| 108 | br label %for.inc4 |
| 109 | |
| 110 | for.inc4: ; preds = %for.inc4.loopexit, %for.cond1.preheader |
| 111 | %x.1.lcssa = phi i32 [ %x.011, %for.cond1.preheader ], [ %0, %for.inc4.loopexit ] |
| 112 | %inc5 = add nuw nsw i32 %j.012, 1 |
| 113 | %indvars.iv.next16 = add i32 %indvars.iv15, %N |
| 114 | %exitcond17 = icmp eq i32 %inc5, %M |
| 115 | br i1 %exitcond17, label %for.end6.loopexit, label %for.cond1.preheader |
| 116 | |
| 117 | for.end6.loopexit: ; preds = %for.inc4 |
| 118 | %x.1.lcssa.lcssa = phi i32 [ %x.1.lcssa, %for.inc4 ] |
| 119 | br label %for.end6 |
| 120 | |
| 121 | for.end6: ; preds = %for.end6.loopexit, %entry |
| 122 | %x.0.lcssa = phi i32 [ %init, %entry ], [ %x.1.lcssa.lcssa, %for.end6.loopexit ] |
| 123 | ret i32 %x.0.lcssa |
| 124 | } |