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: --- !Passed 27; YAML-NEXT: Pass: slp-vectorizer 28; YAML-NEXT: Name: VectorizedList 29; YAML-NEXT: Function: getelementptr_4x32 30; YAML-NEXT: Args: 31; YAML-NEXT: - String: 'SLP vectorized with cost ' 32; YAML-NEXT: - Cost: '11' 33; YAML-NEXT: - String: ' and with tree size ' 34; YAML-NEXT: - TreeSize: '5' 35 36; YAML: --- !Passed 37; YAML-NEXT: Pass: slp-vectorizer 38; YAML-NEXT: Name: VectorizedList 39; YAML-NEXT: Function: getelementptr_4x32 40; YAML-NEXT: Args: 41; YAML-NEXT: - String: 'SLP vectorized with cost ' 42; YAML-NEXT: - Cost: '16' 43; YAML-NEXT: - String: ' and with tree size ' 44; YAML-NEXT: - TreeSize: '3' 45 46define i32 @getelementptr_4x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %y, i32 %z) { 47; CHECK-LABEL: @getelementptr_4x32( 48; CHECK-NEXT: entry: 49; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 [[N:%.*]], 0 50; CHECK-NEXT: br i1 [[CMP31]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]] 51; CHECK: for.body.preheader: 52; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>, i32 [[X:%.*]], i32 1 53; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> [[TMP0]], i32 [[Y:%.*]], i32 2 54; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> [[TMP1]], i32 [[Z:%.*]], i32 3 55; CHECK-NEXT: br label [[FOR_BODY:%.*]] 56; CHECK: for.cond.cleanup.loopexit: 57; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i32> [[TMP21:%.*]], i32 1 58; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] 59; CHECK: for.cond.cleanup: 60; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP3]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ] 61; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]] 62; CHECK: for.body: 63; CHECK-NEXT: [[TMP4:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP21]], [[FOR_BODY]] ] 64; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x i32> [[TMP4]], i32 0 65; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP5]], 1 66; CHECK-NEXT: [[TMP6:%.*]] = insertelement <4 x i32> undef, i32 [[T4]], i32 0 67; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <4 x i32> [[TMP6]], <4 x i32> undef, <4 x i32> zeroinitializer 68; CHECK-NEXT: [[TMP8:%.*]] = add nsw <4 x i32> [[TMP7]], [[TMP2]] 69; CHECK-NEXT: [[TMP9:%.*]] = extractelement <4 x i32> [[TMP8]], i32 0 70; CHECK-NEXT: [[TMP10:%.*]] = sext i32 [[TMP9]] to i64 71; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[G:%.*]], i64 [[TMP10]] 72; CHECK-NEXT: [[T6:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 73; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i32> [[TMP4]], i32 1 74; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[T6]], [[TMP11]] 75; CHECK-NEXT: [[TMP12:%.*]] = extractelement <4 x i32> [[TMP8]], i32 1 76; CHECK-NEXT: [[TMP13:%.*]] = sext i32 [[TMP12]] to i64 77; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP13]] 78; CHECK-NEXT: [[T8:%.*]] = load i32, i32* [[ARRAYIDX5]], align 4 79; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[ADD1]], [[T8]] 80; CHECK-NEXT: [[TMP14:%.*]] = extractelement <4 x i32> [[TMP8]], i32 2 81; CHECK-NEXT: [[TMP15:%.*]] = sext i32 [[TMP14]] to i64 82; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP15]] 83; CHECK-NEXT: [[T10:%.*]] = load i32, i32* [[ARRAYIDX10]], align 4 84; CHECK-NEXT: [[ADD11:%.*]] = add nsw i32 [[ADD6]], [[T10]] 85; CHECK-NEXT: [[TMP16:%.*]] = extractelement <4 x i32> [[TMP8]], i32 3 86; CHECK-NEXT: [[TMP17:%.*]] = sext i32 [[TMP16]] to i64 87; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP17]] 88; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4 89; CHECK-NEXT: [[TMP18:%.*]] = insertelement <2 x i32> undef, i32 [[TMP5]], i32 0 90; CHECK-NEXT: [[TMP19:%.*]] = insertelement <2 x i32> [[TMP18]], i32 [[ADD11]], i32 1 91; CHECK-NEXT: [[TMP20:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1 92; CHECK-NEXT: [[TMP21]] = add nsw <2 x i32> [[TMP19]], [[TMP20]] 93; CHECK-NEXT: [[TMP22:%.*]] = extractelement <2 x i32> [[TMP21]], i32 0 94; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP22]], [[N]] 95; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]] 96; 97entry: 98 %cmp31 = icmp sgt i32 %n, 0 99 br i1 %cmp31, label %for.body.preheader, label %for.cond.cleanup 100 101for.body.preheader: 102 br label %for.body 103 104for.cond.cleanup.loopexit: 105 br label %for.cond.cleanup 106 107for.cond.cleanup: 108 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add16, %for.cond.cleanup.loopexit ] 109 ret i32 %sum.0.lcssa 110 111for.body: 112 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 113 %sum.032 = phi i32 [ 0, %for.body.preheader ], [ %add16, %for.body ] 114 %t4 = shl nsw i32 %indvars.iv, 1 115 %t5 = add nsw i32 %t4, 0 116 %arrayidx = getelementptr inbounds i32, i32* %g, i32 %t5 117 %t6 = load i32, i32* %arrayidx, align 4 118 %add1 = add nsw i32 %t6, %sum.032 119 %t7 = add nsw i32 %t4, %x 120 %arrayidx5 = getelementptr inbounds i32, i32* %g, i32 %t7 121 %t8 = load i32, i32* %arrayidx5, align 4 122 %add6 = add nsw i32 %add1, %t8 123 %t9 = add nsw i32 %t4, %y 124 %arrayidx10 = getelementptr inbounds i32, i32* %g, i32 %t9 125 %t10 = load i32, i32* %arrayidx10, align 4 126 %add11 = add nsw i32 %add6, %t10 127 %t11 = add nsw i32 %t4, %z 128 %arrayidx15 = getelementptr inbounds i32, i32* %g, i32 %t11 129 %t12 = load i32, i32* %arrayidx15, align 4 130 %add16 = add nsw i32 %add11, %t12 131 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 132 %exitcond = icmp eq i32 %indvars.iv.next , %n 133 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body 134} 135 136; YAML: --- !Passed 137; YAML-NEXT: Pass: slp-vectorizer 138; YAML-NEXT: Name: VectorizedList 139; YAML-NEXT: Function: getelementptr_2x32 140; YAML-NEXT: Args: 141; YAML-NEXT: - String: 'SLP vectorized with cost ' 142; YAML-NEXT: - Cost: '11' 143; YAML-NEXT: - String: ' and with tree size ' 144; YAML-NEXT: - TreeSize: '5' 145 146; YAML: --- !Passed 147; YAML-NEXT: Pass: slp-vectorizer 148; YAML-NEXT: Name: VectorizedList 149; YAML-NEXT: Function: getelementptr_2x32 150; YAML-NEXT: Args: 151; YAML-NEXT: - String: 'SLP vectorized with cost ' 152; YAML-NEXT: - Cost: '6' 153; YAML-NEXT: - String: ' and with tree size ' 154; YAML-NEXT: - TreeSize: '3' 155 156define i32 @getelementptr_2x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %y, i32 %z) { 157; CHECK-LABEL: @getelementptr_2x32( 158; CHECK-NEXT: entry: 159; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 [[N:%.*]], 0 160; CHECK-NEXT: br i1 [[CMP31]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]] 161; CHECK: for.body.preheader: 162; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0 163; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> [[TMP0]], i32 [[Z:%.*]], i32 1 164; CHECK-NEXT: br label [[FOR_BODY:%.*]] 165; CHECK: for.cond.cleanup.loopexit: 166; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i32> [[TMP18:%.*]], i32 1 167; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] 168; CHECK: for.cond.cleanup: 169; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP2]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ] 170; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]] 171; CHECK: for.body: 172; CHECK-NEXT: [[TMP3:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP18]], [[FOR_BODY]] ] 173; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i32> [[TMP3]], i32 0 174; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP4]], 1 175; CHECK-NEXT: [[TMP5:%.*]] = sext i32 [[T4]] to i64 176; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[G:%.*]], i64 [[TMP5]] 177; CHECK-NEXT: [[T6:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 178; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x i32> [[TMP3]], i32 1 179; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[T6]], [[TMP6]] 180; CHECK-NEXT: [[T7:%.*]] = or i32 [[T4]], 1 181; CHECK-NEXT: [[TMP7:%.*]] = sext i32 [[T7]] to i64 182; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP7]] 183; CHECK-NEXT: [[T8:%.*]] = load i32, i32* [[ARRAYIDX5]], align 4 184; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[ADD1]], [[T8]] 185; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x i32> undef, i32 [[T4]], i32 0 186; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <2 x i32> [[TMP8]], <2 x i32> undef, <2 x i32> zeroinitializer 187; CHECK-NEXT: [[TMP10:%.*]] = add nsw <2 x i32> [[TMP9]], [[TMP1]] 188; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i32> [[TMP10]], i32 0 189; CHECK-NEXT: [[TMP12:%.*]] = sext i32 [[TMP11]] to i64 190; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP12]] 191; CHECK-NEXT: [[T10:%.*]] = load i32, i32* [[ARRAYIDX10]], align 4 192; CHECK-NEXT: [[ADD11:%.*]] = add nsw i32 [[ADD6]], [[T10]] 193; CHECK-NEXT: [[TMP13:%.*]] = extractelement <2 x i32> [[TMP10]], i32 1 194; CHECK-NEXT: [[TMP14:%.*]] = sext i32 [[TMP13]] to i64 195; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP14]] 196; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4 197; CHECK-NEXT: [[TMP15:%.*]] = insertelement <2 x i32> undef, i32 [[TMP4]], i32 0 198; CHECK-NEXT: [[TMP16:%.*]] = insertelement <2 x i32> [[TMP15]], i32 [[ADD11]], i32 1 199; CHECK-NEXT: [[TMP17:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1 200; CHECK-NEXT: [[TMP18]] = add nsw <2 x i32> [[TMP16]], [[TMP17]] 201; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x i32> [[TMP18]], i32 0 202; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP19]], [[N]] 203; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]] 204; 205entry: 206 %cmp31 = icmp sgt i32 %n, 0 207 br i1 %cmp31, label %for.body.preheader, label %for.cond.cleanup 208 209for.body.preheader: 210 br label %for.body 211 212for.cond.cleanup.loopexit: 213 br label %for.cond.cleanup 214 215for.cond.cleanup: 216 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add16, %for.cond.cleanup.loopexit ] 217 ret i32 %sum.0.lcssa 218 219for.body: 220 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 221 %sum.032 = phi i32 [ 0, %for.body.preheader ], [ %add16, %for.body ] 222 %t4 = shl nsw i32 %indvars.iv, 1 223 %t5 = add nsw i32 %t4, 0 224 %arrayidx = getelementptr inbounds i32, i32* %g, i32 %t5 225 %t6 = load i32, i32* %arrayidx, align 4 226 %add1 = add nsw i32 %t6, %sum.032 227 %t7 = add nsw i32 %t4, 1 228 %arrayidx5 = getelementptr inbounds i32, i32* %g, i32 %t7 229 %t8 = load i32, i32* %arrayidx5, align 4 230 %add6 = add nsw i32 %add1, %t8 231 %t9 = add nsw i32 %t4, %y 232 %arrayidx10 = getelementptr inbounds i32, i32* %g, i32 %t9 233 %t10 = load i32, i32* %arrayidx10, align 4 234 %add11 = add nsw i32 %add6, %t10 235 %t11 = add nsw i32 %t4, %z 236 %arrayidx15 = getelementptr inbounds i32, i32* %g, i32 %t11 237 %t12 = load i32, i32* %arrayidx15, align 4 238 %add16 = add nsw i32 %add11, %t12 239 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 240 %exitcond = icmp eq i32 %indvars.iv.next , %n 241 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body 242} 243