1; RUN: opt -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 < %s | FileCheck %s 2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4 5; Check the scenario where we have an unknown Stride, which happens to also be 6; the loop iteration count, so if we specialize the loop for the Stride==1 case, 7; this also implies that the loop will iterate no more than a single iteration, 8; as in the following example: 9; 10; unsigned int N; 11; int tmp = 0; 12; for(unsigned int k=0;k<N;k++) { 13; tmp+=(int)B[k*N+j]; 14; } 15; 16; We check here that the following runtime scev guard for Stride==1 is NOT generated: 17; vector.scevcheck: 18; %ident.check = icmp ne i32 %N, 1 19; %0 = or i1 false, %ident.check 20; br i1 %0, label %scalar.ph, label %vector.ph 21; Instead the loop is vectorized with an unknown stride. 22 23; CHECK-LABEL: @foo1 24; CHECK: for.body.lr.ph 25; CHECK-NOT: %ident.check = icmp ne i32 %N, 1 26; CHECK-NOT: %[[TEST:[0-9]+]] = or i1 false, %ident.check 27; CHECK-NOT: br i1 %[[TEST]], label %scalar.ph, label %vector.ph 28; CHECK: vector.ph 29; CHECK: vector.body 30; CHECK: <4 x i32> 31; CHECK: middle.block 32; CHECK: scalar.ph 33 34 35define i32 @foo1(i32 %N, i16* nocapture readnone %A, i16* nocapture readonly %B, i32 %i, i32 %j) { 36entry: 37 %cmp8 = icmp eq i32 %N, 0 38 br i1 %cmp8, label %for.end, label %for.body.lr.ph 39 40for.body.lr.ph: 41 br label %for.body 42 43for.body: 44 %tmp.010 = phi i32 [ 0, %for.body.lr.ph ], [ %add1, %for.body ] 45 %k.09 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ] 46 %mul = mul i32 %k.09, %N 47 %add = add i32 %mul, %j 48 %arrayidx = getelementptr inbounds i16, i16* %B, i32 %add 49 %0 = load i16, i16* %arrayidx, align 2 50 %conv = sext i16 %0 to i32 51 %add1 = add nsw i32 %tmp.010, %conv 52 %inc = add nuw i32 %k.09, 1 53 %exitcond = icmp eq i32 %inc, %N 54 br i1 %exitcond, label %for.end.loopexit, label %for.body 55 56for.end.loopexit: 57 %add1.lcssa = phi i32 [ %add1, %for.body ] 58 br label %for.end 59 60for.end: 61 %tmp.0.lcssa = phi i32 [ 0, %entry ], [ %add1.lcssa, %for.end.loopexit ] 62 ret i32 %tmp.0.lcssa 63} 64 65 66; Check the same, but also where the Stride and the loop iteration count 67; are not of the same data type. 68; 69; unsigned short N; 70; int tmp = 0; 71; for(unsigned int k=0;k<N;k++) { 72; tmp+=(int)B[k*N+j]; 73; } 74; 75; We check here that the following runtime scev guard for Stride==1 is NOT generated: 76; vector.scevcheck: 77; %ident.check = icmp ne i16 %N, 1 78; %0 = or i1 false, %ident.check 79; br i1 %0, label %scalar.ph, label %vector.ph 80 81 82; CHECK-LABEL: @foo2 83; CHECK: for.body.lr.ph 84; CHECK-NOT: %ident.check = icmp ne i16 %N, 1 85; CHECK-NOT: %[[TEST:[0-9]+]] = or i1 false, %ident.check 86; CHECK-NOT: br i1 %[[TEST]], label %scalar.ph, label %vector.ph 87; CHECK: vector.ph 88; CHECK: vector.body 89; CHECK: <4 x i32> 90; CHECK: middle.block 91; CHECK: scalar.ph 92 93define i32 @foo2(i16 zeroext %N, i16* nocapture readnone %A, i16* nocapture readonly %B, i32 %i, i32 %j) { 94entry: 95 %conv = zext i16 %N to i32 96 %cmp11 = icmp eq i16 %N, 0 97 br i1 %cmp11, label %for.end, label %for.body.lr.ph 98 99for.body.lr.ph: 100 br label %for.body 101 102for.body: 103 %tmp.013 = phi i32 [ 0, %for.body.lr.ph ], [ %add4, %for.body ] 104 %k.012 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ] 105 %mul = mul nuw i32 %k.012, %conv 106 %add = add i32 %mul, %j 107 %arrayidx = getelementptr inbounds i16, i16* %B, i32 %add 108 %0 = load i16, i16* %arrayidx, align 2 109 %conv3 = sext i16 %0 to i32 110 %add4 = add nsw i32 %tmp.013, %conv3 111 %inc = add nuw nsw i32 %k.012, 1 112 %exitcond = icmp eq i32 %inc, %conv 113 br i1 %exitcond, label %for.end.loopexit, label %for.body 114 115for.end.loopexit: 116 %add4.lcssa = phi i32 [ %add4, %for.body ] 117 br label %for.end 118 119for.end: 120 %tmp.0.lcssa = phi i32 [ 0, %entry ], [ %add4.lcssa, %for.end.loopexit ] 121 ret i32 %tmp.0.lcssa 122} 123