1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -slp-vectorizer -slp-threshold=-18 -dce -instcombine -pass-remarks-output=%t < %s | FileCheck %s 3; RUN: cat %t | FileCheck -check-prefix=YAML %s 4; RUN: opt -S -passes='slp-vectorizer,dce,instcombine' -slp-threshold=-18 -pass-remarks-output=%t < %s | FileCheck %s 5; RUN: cat %t | FileCheck -check-prefix=YAML %s 6 7 8target datalayout = "e-m:e-i32:64-i128:128-n32:64-S128" 9target triple = "aarch64--linux-gnu" 10 11; These tests check that we remove from consideration pairs of seed 12; getelementptrs when they are known to have a constant difference. Such pairs 13; are likely not good candidates for vectorization since one can be computed 14; from the other. We use an unprofitable threshold to force vectorization. 15; 16; int getelementptr(int *g, int n, int w, int x, int y, int z) { 17; int sum = 0; 18; for (int i = 0; i < n ; ++i) { 19; sum += g[2*i + w]; sum += g[2*i + x]; 20; sum += g[2*i + y]; sum += g[2*i + z]; 21; } 22; return sum; 23; } 24; 25 26; YAML-LABEL: Function: getelementptr_4x32 27; YAML-NEXT: Args: 28; YAML-NEXT: - String: 'SLP vectorized with cost ' 29; YAML-NEXT: - Cost: '11' 30; YAML-NEXT: - String: ' and with tree size ' 31; YAML-NEXT: - TreeSize: '5' 32 33; YAML: --- !Passed 34; YAML-NEXT: Pass: slp-vectorizer 35; YAML-NEXT: Name: VectorizedList 36; YAML-NEXT: Function: getelementptr_4x32 37; YAML-NEXT: Args: 38; YAML-NEXT: - String: 'SLP vectorized with cost ' 39; YAML-NEXT: - Cost: '6' 40; YAML-NEXT: - String: ' and with tree size ' 41; YAML-NEXT: - TreeSize: '3' 42 43define i32 @getelementptr_4x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %y, i32 %z) { 44; CHECK-LABEL: @getelementptr_4x32( 45; CHECK-NEXT: entry: 46; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 [[N:%.*]], 0 47; CHECK-NEXT: br i1 [[CMP31]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]] 48; CHECK: for.body.preheader: 49; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i32> <i32 0, i32 undef>, i32 [[X:%.*]], i32 1 50; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0 51; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[Z:%.*]], i32 1 52; CHECK-NEXT: br label [[FOR_BODY:%.*]] 53; CHECK: for.cond.cleanup.loopexit: 54; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i32> [[TMP22:%.*]], i32 1 55; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] 56; CHECK: for.cond.cleanup: 57; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP3]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ] 58; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]] 59; CHECK: for.body: 60; CHECK-NEXT: [[TMP4:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP22]], [[FOR_BODY]] ] 61; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x i32> [[TMP4]], i32 0 62; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP5]], 1 63; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x i32> undef, i32 [[T4]], i32 0 64; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> undef, <2 x i32> zeroinitializer 65; CHECK-NEXT: [[TMP8:%.*]] = add nsw <2 x i32> [[TMP7]], [[TMP0]] 66; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x i32> [[TMP8]], i32 0 67; CHECK-NEXT: [[TMP10:%.*]] = sext i32 [[TMP9]] to i64 68; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[G:%.*]], i64 [[TMP10]] 69; CHECK-NEXT: [[T6:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 70; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i32> [[TMP4]], i32 1 71; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[T6]], [[TMP11]] 72; CHECK-NEXT: [[TMP12:%.*]] = extractelement <2 x i32> [[TMP8]], i32 1 73; CHECK-NEXT: [[TMP13:%.*]] = sext i32 [[TMP12]] to i64 74; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP13]] 75; CHECK-NEXT: [[T8:%.*]] = load i32, i32* [[ARRAYIDX5]], align 4 76; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[ADD1]], [[T8]] 77; CHECK-NEXT: [[TMP14:%.*]] = add nsw <2 x i32> [[TMP7]], [[TMP2]] 78; CHECK-NEXT: [[TMP15:%.*]] = extractelement <2 x i32> [[TMP14]], i32 0 79; CHECK-NEXT: [[TMP16:%.*]] = sext i32 [[TMP15]] to i64 80; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP16]] 81; CHECK-NEXT: [[T10:%.*]] = load i32, i32* [[ARRAYIDX10]], align 4 82; CHECK-NEXT: [[ADD11:%.*]] = add nsw i32 [[ADD6]], [[T10]] 83; CHECK-NEXT: [[TMP17:%.*]] = extractelement <2 x i32> [[TMP14]], i32 1 84; CHECK-NEXT: [[TMP18:%.*]] = sext i32 [[TMP17]] to i64 85; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP18]] 86; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4 87; CHECK-NEXT: [[TMP19:%.*]] = insertelement <2 x i32> undef, i32 [[TMP5]], i32 0 88; CHECK-NEXT: [[TMP20:%.*]] = insertelement <2 x i32> [[TMP19]], i32 [[ADD11]], i32 1 89; CHECK-NEXT: [[TMP21:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1 90; CHECK-NEXT: [[TMP22]] = add nsw <2 x i32> [[TMP20]], [[TMP21]] 91; CHECK-NEXT: [[TMP23:%.*]] = extractelement <2 x i32> [[TMP22]], i32 0 92; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP23]], [[N]] 93; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]] 94; 95entry: 96 %cmp31 = icmp sgt i32 %n, 0 97 br i1 %cmp31, label %for.body.preheader, label %for.cond.cleanup 98 99for.body.preheader: 100 br label %for.body 101 102for.cond.cleanup.loopexit: 103 br label %for.cond.cleanup 104 105for.cond.cleanup: 106 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add16, %for.cond.cleanup.loopexit ] 107 ret i32 %sum.0.lcssa 108 109for.body: 110 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 111 %sum.032 = phi i32 [ 0, %for.body.preheader ], [ %add16, %for.body ] 112 %t4 = shl nsw i32 %indvars.iv, 1 113 %t5 = add nsw i32 %t4, 0 114 %arrayidx = getelementptr inbounds i32, i32* %g, i32 %t5 115 %t6 = load i32, i32* %arrayidx, align 4 116 %add1 = add nsw i32 %t6, %sum.032 117 %t7 = add nsw i32 %t4, %x 118 %arrayidx5 = getelementptr inbounds i32, i32* %g, i32 %t7 119 %t8 = load i32, i32* %arrayidx5, align 4 120 %add6 = add nsw i32 %add1, %t8 121 %t9 = add nsw i32 %t4, %y 122 %arrayidx10 = getelementptr inbounds i32, i32* %g, i32 %t9 123 %t10 = load i32, i32* %arrayidx10, align 4 124 %add11 = add nsw i32 %add6, %t10 125 %t11 = add nsw i32 %t4, %z 126 %arrayidx15 = getelementptr inbounds i32, i32* %g, i32 %t11 127 %t12 = load i32, i32* %arrayidx15, align 4 128 %add16 = add nsw i32 %add11, %t12 129 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 130 %exitcond = icmp eq i32 %indvars.iv.next , %n 131 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body 132} 133 134; YAML-LABEL: Function: getelementptr_2x32 135; YAML-NEXT: Args: 136; YAML-NEXT: - String: 'SLP vectorized with cost ' 137; YAML-NEXT: - Cost: '11' 138; YAML-NEXT: - String: ' and with tree size ' 139; YAML-NEXT: - TreeSize: '5' 140 141; YAML: --- !Passed 142; YAML-NEXT: Pass: slp-vectorizer 143; YAML-NEXT: Name: VectorizedList 144; YAML-NEXT: Function: getelementptr_2x32 145; YAML-NEXT: Args: 146; YAML-NEXT: - String: 'SLP vectorized with cost ' 147; YAML-NEXT: - Cost: '6' 148; YAML-NEXT: - String: ' and with tree size ' 149; YAML-NEXT: - TreeSize: '3' 150 151define i32 @getelementptr_2x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %y, i32 %z) { 152; CHECK-LABEL: @getelementptr_2x32( 153; CHECK-NEXT: entry: 154; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 [[N:%.*]], 0 155; CHECK-NEXT: br i1 [[CMP31]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]] 156; CHECK: for.body.preheader: 157; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0 158; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> [[TMP0]], i32 [[Z:%.*]], i32 1 159; CHECK-NEXT: br label [[FOR_BODY:%.*]] 160; CHECK: for.cond.cleanup.loopexit: 161; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i32> [[TMP18:%.*]], i32 1 162; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] 163; CHECK: for.cond.cleanup: 164; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP2]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ] 165; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]] 166; CHECK: for.body: 167; CHECK-NEXT: [[TMP3:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP18]], [[FOR_BODY]] ] 168; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i32> [[TMP3]], i32 0 169; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP4]], 1 170; CHECK-NEXT: [[TMP5:%.*]] = sext i32 [[T4]] to i64 171; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[G:%.*]], i64 [[TMP5]] 172; CHECK-NEXT: [[T6:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 173; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x i32> [[TMP3]], i32 1 174; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[T6]], [[TMP6]] 175; CHECK-NEXT: [[T7:%.*]] = or i32 [[T4]], 1 176; CHECK-NEXT: [[TMP7:%.*]] = sext i32 [[T7]] to i64 177; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP7]] 178; CHECK-NEXT: [[T8:%.*]] = load i32, i32* [[ARRAYIDX5]], align 4 179; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[ADD1]], [[T8]] 180; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x i32> undef, i32 [[T4]], i32 0 181; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <2 x i32> [[TMP8]], <2 x i32> undef, <2 x i32> zeroinitializer 182; CHECK-NEXT: [[TMP10:%.*]] = add nsw <2 x i32> [[TMP9]], [[TMP1]] 183; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i32> [[TMP10]], i32 0 184; CHECK-NEXT: [[TMP12:%.*]] = sext i32 [[TMP11]] to i64 185; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP12]] 186; CHECK-NEXT: [[T10:%.*]] = load i32, i32* [[ARRAYIDX10]], align 4 187; CHECK-NEXT: [[ADD11:%.*]] = add nsw i32 [[ADD6]], [[T10]] 188; CHECK-NEXT: [[TMP13:%.*]] = extractelement <2 x i32> [[TMP10]], i32 1 189; CHECK-NEXT: [[TMP14:%.*]] = sext i32 [[TMP13]] to i64 190; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP14]] 191; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4 192; CHECK-NEXT: [[TMP15:%.*]] = insertelement <2 x i32> undef, i32 [[TMP4]], i32 0 193; CHECK-NEXT: [[TMP16:%.*]] = insertelement <2 x i32> [[TMP15]], i32 [[ADD11]], i32 1 194; CHECK-NEXT: [[TMP17:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1 195; CHECK-NEXT: [[TMP18]] = add nsw <2 x i32> [[TMP16]], [[TMP17]] 196; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x i32> [[TMP18]], i32 0 197; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP19]], [[N]] 198; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]] 199; 200entry: 201 %cmp31 = icmp sgt i32 %n, 0 202 br i1 %cmp31, label %for.body.preheader, label %for.cond.cleanup 203 204for.body.preheader: 205 br label %for.body 206 207for.cond.cleanup.loopexit: 208 br label %for.cond.cleanup 209 210for.cond.cleanup: 211 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add16, %for.cond.cleanup.loopexit ] 212 ret i32 %sum.0.lcssa 213 214for.body: 215 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 216 %sum.032 = phi i32 [ 0, %for.body.preheader ], [ %add16, %for.body ] 217 %t4 = shl nsw i32 %indvars.iv, 1 218 %t5 = add nsw i32 %t4, 0 219 %arrayidx = getelementptr inbounds i32, i32* %g, i32 %t5 220 %t6 = load i32, i32* %arrayidx, align 4 221 %add1 = add nsw i32 %t6, %sum.032 222 %t7 = add nsw i32 %t4, 1 223 %arrayidx5 = getelementptr inbounds i32, i32* %g, i32 %t7 224 %t8 = load i32, i32* %arrayidx5, align 4 225 %add6 = add nsw i32 %add1, %t8 226 %t9 = add nsw i32 %t4, %y 227 %arrayidx10 = getelementptr inbounds i32, i32* %g, i32 %t9 228 %t10 = load i32, i32* %arrayidx10, align 4 229 %add11 = add nsw i32 %add6, %t10 230 %t11 = add nsw i32 %t4, %z 231 %arrayidx15 = getelementptr inbounds i32, i32* %g, i32 %t11 232 %t12 = load i32, i32* %arrayidx15, align 4 233 %add16 = add nsw i32 %add11, %t12 234 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 235 %exitcond = icmp eq i32 %indvars.iv.next , %n 236 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body 237} 238