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