1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s 3 4; See https://reviews.llvm.org/D70068 and https://reviews.llvm.org/D70587 for context 5 6; Checks that vector insertvalues into the struct become SLP seeds. 7define { <2 x float>, <2 x float> } @StructOfVectors(float *%Ptr) { 8; CHECK-LABEL: @StructOfVectors( 9; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i64 0 10; CHECK-NEXT: [[TMP1:%.*]] = bitcast float* [[GEP0]] to <4 x float>* 11; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4 12; CHECK-NEXT: [[TMP3:%.*]] = fadd fast <4 x float> [[TMP2]], <float 1.100000e+01, float 1.200000e+01, float 1.300000e+01, float 1.400000e+01> 13; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x float> [[TMP3]], <4 x float> poison, <2 x i32> <i32 0, i32 1> 14; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[TMP3]], <4 x float> poison, <2 x i32> <i32 2, i32 3> 15; CHECK-NEXT: [[RET0:%.*]] = insertvalue { <2 x float>, <2 x float> } undef, <2 x float> [[TMP4]], 0 16; CHECK-NEXT: [[RET1:%.*]] = insertvalue { <2 x float>, <2 x float> } [[RET0]], <2 x float> [[TMP5]], 1 17; CHECK-NEXT: ret { <2 x float>, <2 x float> } [[RET1]] 18; 19 %GEP0 = getelementptr inbounds float, float* %Ptr, i64 0 20 %L0 = load float, float * %GEP0 21 %GEP1 = getelementptr inbounds float, float* %Ptr, i64 1 22 %L1 = load float, float * %GEP1 23 %GEP2 = getelementptr inbounds float, float* %Ptr, i64 2 24 %L2 = load float, float * %GEP2 25 %GEP3 = getelementptr inbounds float, float* %Ptr, i64 3 26 %L3 = load float, float * %GEP3 27 28 %Fadd0 = fadd fast float %L0, 1.1e+01 29 %Fadd1 = fadd fast float %L1, 1.2e+01 30 %Fadd2 = fadd fast float %L2, 1.3e+01 31 %Fadd3 = fadd fast float %L3, 1.4e+01 32 33 %VecIn0 = insertelement <2 x float> undef, float %Fadd0, i64 0 34 %VecIn1 = insertelement <2 x float> %VecIn0, float %Fadd1, i64 1 35 36 %VecIn2 = insertelement <2 x float> undef, float %Fadd2, i64 0 37 %VecIn3 = insertelement <2 x float> %VecIn2, float %Fadd3, i64 1 38 39 %Ret0 = insertvalue {<2 x float>, <2 x float>} undef, <2 x float> %VecIn1, 0 40 %Ret1 = insertvalue {<2 x float>, <2 x float>} %Ret0, <2 x float> %VecIn3, 1 41 ret {<2 x float>, <2 x float>} %Ret1 42} 43 44%StructTy = type { float, float} 45 46define [2 x %StructTy] @ArrayOfStruct(float *%Ptr) { 47; CHECK-LABEL: @ArrayOfStruct( 48; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i64 0 49; CHECK-NEXT: [[TMP1:%.*]] = bitcast float* [[GEP0]] to <4 x float>* 50; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4 51; CHECK-NEXT: [[TMP3:%.*]] = fadd fast <4 x float> [[TMP2]], <float 1.100000e+01, float 1.200000e+01, float 1.300000e+01, float 1.400000e+01> 52; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP3]], i32 0 53; CHECK-NEXT: [[STRUCTIN0:%.*]] = insertvalue [[STRUCTTY:%.*]] undef, float [[TMP4]], 0 54; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP3]], i32 1 55; CHECK-NEXT: [[STRUCTIN1:%.*]] = insertvalue [[STRUCTTY]] [[STRUCTIN0]], float [[TMP5]], 1 56; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP3]], i32 2 57; CHECK-NEXT: [[STRUCTIN2:%.*]] = insertvalue [[STRUCTTY]] undef, float [[TMP6]], 0 58; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[TMP3]], i32 3 59; CHECK-NEXT: [[STRUCTIN3:%.*]] = insertvalue [[STRUCTTY]] [[STRUCTIN2]], float [[TMP7]], 1 60; CHECK-NEXT: [[RET0:%.*]] = insertvalue [2 x %StructTy] undef, [[STRUCTTY]] [[STRUCTIN1]], 0 61; CHECK-NEXT: [[RET1:%.*]] = insertvalue [2 x %StructTy] [[RET0]], [[STRUCTTY]] [[STRUCTIN3]], 1 62; CHECK-NEXT: ret [2 x %StructTy] [[RET1]] 63; 64 %GEP0 = getelementptr inbounds float, float* %Ptr, i64 0 65 %L0 = load float, float * %GEP0 66 %GEP1 = getelementptr inbounds float, float* %Ptr, i64 1 67 %L1 = load float, float * %GEP1 68 %GEP2 = getelementptr inbounds float, float* %Ptr, i64 2 69 %L2 = load float, float * %GEP2 70 %GEP3 = getelementptr inbounds float, float* %Ptr, i64 3 71 %L3 = load float, float * %GEP3 72 73 %Fadd0 = fadd fast float %L0, 1.1e+01 74 %Fadd1 = fadd fast float %L1, 1.2e+01 75 %Fadd2 = fadd fast float %L2, 1.3e+01 76 %Fadd3 = fadd fast float %L3, 1.4e+01 77 78 %StructIn0 = insertvalue %StructTy undef, float %Fadd0, 0 79 %StructIn1 = insertvalue %StructTy %StructIn0, float %Fadd1, 1 80 81 %StructIn2 = insertvalue %StructTy undef, float %Fadd2, 0 82 %StructIn3 = insertvalue %StructTy %StructIn2, float %Fadd3, 1 83 84 %Ret0 = insertvalue [2 x %StructTy] undef, %StructTy %StructIn1, 0 85 %Ret1 = insertvalue [2 x %StructTy] %Ret0, %StructTy %StructIn3, 1 86 ret [2 x %StructTy] %Ret1 87} 88 89define {%StructTy, %StructTy} @StructOfStruct(float *%Ptr) { 90; CHECK-LABEL: @StructOfStruct( 91; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i64 0 92; CHECK-NEXT: [[TMP1:%.*]] = bitcast float* [[GEP0]] to <4 x float>* 93; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4 94; CHECK-NEXT: [[TMP3:%.*]] = fadd fast <4 x float> [[TMP2]], <float 1.100000e+01, float 1.200000e+01, float 1.300000e+01, float 1.400000e+01> 95; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP3]], i32 0 96; CHECK-NEXT: [[STRUCTIN0:%.*]] = insertvalue [[STRUCTTY:%.*]] undef, float [[TMP4]], 0 97; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP3]], i32 1 98; CHECK-NEXT: [[STRUCTIN1:%.*]] = insertvalue [[STRUCTTY]] [[STRUCTIN0]], float [[TMP5]], 1 99; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP3]], i32 2 100; CHECK-NEXT: [[STRUCTIN2:%.*]] = insertvalue [[STRUCTTY]] undef, float [[TMP6]], 0 101; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[TMP3]], i32 3 102; CHECK-NEXT: [[STRUCTIN3:%.*]] = insertvalue [[STRUCTTY]] [[STRUCTIN2]], float [[TMP7]], 1 103; CHECK-NEXT: [[RET0:%.*]] = insertvalue { [[STRUCTTY]], [[STRUCTTY]] } undef, [[STRUCTTY]] [[STRUCTIN1]], 0 104; CHECK-NEXT: [[RET1:%.*]] = insertvalue { [[STRUCTTY]], [[STRUCTTY]] } [[RET0]], [[STRUCTTY]] [[STRUCTIN3]], 1 105; CHECK-NEXT: ret { [[STRUCTTY]], [[STRUCTTY]] } [[RET1]] 106; 107 %GEP0 = getelementptr inbounds float, float* %Ptr, i64 0 108 %L0 = load float, float * %GEP0 109 %GEP1 = getelementptr inbounds float, float* %Ptr, i64 1 110 %L1 = load float, float * %GEP1 111 %GEP2 = getelementptr inbounds float, float* %Ptr, i64 2 112 %L2 = load float, float * %GEP2 113 %GEP3 = getelementptr inbounds float, float* %Ptr, i64 3 114 %L3 = load float, float * %GEP3 115 116 %Fadd0 = fadd fast float %L0, 1.1e+01 117 %Fadd1 = fadd fast float %L1, 1.2e+01 118 %Fadd2 = fadd fast float %L2, 1.3e+01 119 %Fadd3 = fadd fast float %L3, 1.4e+01 120 121 %StructIn0 = insertvalue %StructTy undef, float %Fadd0, 0 122 %StructIn1 = insertvalue %StructTy %StructIn0, float %Fadd1, 1 123 124 %StructIn2 = insertvalue %StructTy undef, float %Fadd2, 0 125 %StructIn3 = insertvalue %StructTy %StructIn2, float %Fadd3, 1 126 127 %Ret0 = insertvalue {%StructTy, %StructTy} undef, %StructTy %StructIn1, 0 128 %Ret1 = insertvalue {%StructTy, %StructTy} %Ret0, %StructTy %StructIn3, 1 129 ret {%StructTy, %StructTy} %Ret1 130} 131 132define {%StructTy, float, float} @NonHomogeneousStruct(float *%Ptr) { 133; CHECK-LABEL: @NonHomogeneousStruct( 134; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i64 0 135; CHECK-NEXT: [[L0:%.*]] = load float, float* [[GEP0]], align 4 136; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds float, float* [[PTR]], i64 1 137; CHECK-NEXT: [[L1:%.*]] = load float, float* [[GEP1]], align 4 138; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds float, float* [[PTR]], i64 2 139; CHECK-NEXT: [[L2:%.*]] = load float, float* [[GEP2]], align 4 140; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds float, float* [[PTR]], i64 3 141; CHECK-NEXT: [[L3:%.*]] = load float, float* [[GEP3]], align 4 142; CHECK-NEXT: [[FADD0:%.*]] = fadd fast float [[L0]], 1.100000e+01 143; CHECK-NEXT: [[FADD1:%.*]] = fadd fast float [[L1]], 1.200000e+01 144; CHECK-NEXT: [[FADD2:%.*]] = fadd fast float [[L2]], 1.300000e+01 145; CHECK-NEXT: [[FADD3:%.*]] = fadd fast float [[L3]], 1.400000e+01 146; CHECK-NEXT: [[STRUCTIN0:%.*]] = insertvalue [[STRUCTTY:%.*]] undef, float [[FADD0]], 0 147; CHECK-NEXT: [[STRUCTIN1:%.*]] = insertvalue [[STRUCTTY]] [[STRUCTIN0]], float [[FADD1]], 1 148; CHECK-NEXT: [[RET0:%.*]] = insertvalue { [[STRUCTTY]], float, float } undef, [[STRUCTTY]] [[STRUCTIN1]], 0 149; CHECK-NEXT: [[RET1:%.*]] = insertvalue { [[STRUCTTY]], float, float } [[RET0]], float [[FADD2]], 1 150; CHECK-NEXT: [[RET2:%.*]] = insertvalue { [[STRUCTTY]], float, float } [[RET1]], float [[FADD3]], 2 151; CHECK-NEXT: ret { [[STRUCTTY]], float, float } [[RET2]] 152; 153 %GEP0 = getelementptr inbounds float, float* %Ptr, i64 0 154 %L0 = load float, float * %GEP0 155 %GEP1 = getelementptr inbounds float, float* %Ptr, i64 1 156 %L1 = load float, float * %GEP1 157 %GEP2 = getelementptr inbounds float, float* %Ptr, i64 2 158 %L2 = load float, float * %GEP2 159 %GEP3 = getelementptr inbounds float, float* %Ptr, i64 3 160 %L3 = load float, float * %GEP3 161 162 %Fadd0 = fadd fast float %L0, 1.1e+01 163 %Fadd1 = fadd fast float %L1, 1.2e+01 164 %Fadd2 = fadd fast float %L2, 1.3e+01 165 %Fadd3 = fadd fast float %L3, 1.4e+01 166 167 %StructIn0 = insertvalue %StructTy undef, float %Fadd0, 0 168 %StructIn1 = insertvalue %StructTy %StructIn0, float %Fadd1, 1 169 170 %Ret0 = insertvalue {%StructTy, float, float} undef, %StructTy %StructIn1, 0 171 %Ret1 = insertvalue {%StructTy, float, float} %Ret0, float %Fadd2, 1 172 %Ret2 = insertvalue {%StructTy, float, float} %Ret1, float %Fadd3, 2 173 ret {%StructTy, float, float} %Ret2 174} 175 176%Struct1Ty = type { i16, i16 } 177%Struct2Ty = type { %Struct1Ty, %Struct1Ty} 178 179define {%Struct2Ty, %Struct2Ty} @StructOfStructOfStruct(i16 *%Ptr) { 180; CHECK-LABEL: @StructOfStructOfStruct( 181; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds i16, i16* [[PTR:%.*]], i64 0 182; CHECK-NEXT: [[TMP1:%.*]] = bitcast i16* [[GEP0]] to <8 x i16>* 183; CHECK-NEXT: [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2 184; CHECK-NEXT: [[TMP3:%.*]] = add <8 x i16> [[TMP2]], <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8> 185; CHECK-NEXT: [[TMP4:%.*]] = extractelement <8 x i16> [[TMP3]], i32 0 186; CHECK-NEXT: [[STRUCTIN0:%.*]] = insertvalue [[STRUCT1TY:%.*]] undef, i16 [[TMP4]], 0 187; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x i16> [[TMP3]], i32 1 188; CHECK-NEXT: [[STRUCTIN1:%.*]] = insertvalue [[STRUCT1TY]] [[STRUCTIN0]], i16 [[TMP5]], 1 189; CHECK-NEXT: [[TMP6:%.*]] = extractelement <8 x i16> [[TMP3]], i32 2 190; CHECK-NEXT: [[STRUCTIN2:%.*]] = insertvalue [[STRUCT1TY]] undef, i16 [[TMP6]], 0 191; CHECK-NEXT: [[TMP7:%.*]] = extractelement <8 x i16> [[TMP3]], i32 3 192; CHECK-NEXT: [[STRUCTIN3:%.*]] = insertvalue [[STRUCT1TY]] [[STRUCTIN2]], i16 [[TMP7]], 1 193; CHECK-NEXT: [[TMP8:%.*]] = extractelement <8 x i16> [[TMP3]], i32 4 194; CHECK-NEXT: [[STRUCTIN4:%.*]] = insertvalue [[STRUCT1TY]] undef, i16 [[TMP8]], 0 195; CHECK-NEXT: [[TMP9:%.*]] = extractelement <8 x i16> [[TMP3]], i32 5 196; CHECK-NEXT: [[STRUCTIN5:%.*]] = insertvalue [[STRUCT1TY]] [[STRUCTIN4]], i16 [[TMP9]], 1 197; CHECK-NEXT: [[TMP10:%.*]] = extractelement <8 x i16> [[TMP3]], i32 6 198; CHECK-NEXT: [[STRUCTIN6:%.*]] = insertvalue [[STRUCT1TY]] undef, i16 [[TMP10]], 0 199; CHECK-NEXT: [[TMP11:%.*]] = extractelement <8 x i16> [[TMP3]], i32 7 200; CHECK-NEXT: [[STRUCTIN7:%.*]] = insertvalue [[STRUCT1TY]] [[STRUCTIN6]], i16 [[TMP11]], 1 201; CHECK-NEXT: [[STRUCT2IN0:%.*]] = insertvalue [[STRUCT2TY:%.*]] undef, [[STRUCT1TY]] [[STRUCTIN1]], 0 202; CHECK-NEXT: [[STRUCT2IN1:%.*]] = insertvalue [[STRUCT2TY]] [[STRUCT2IN0]], [[STRUCT1TY]] [[STRUCTIN3]], 1 203; CHECK-NEXT: [[STRUCT2IN2:%.*]] = insertvalue [[STRUCT2TY]] undef, [[STRUCT1TY]] [[STRUCTIN5]], 0 204; CHECK-NEXT: [[STRUCT2IN3:%.*]] = insertvalue [[STRUCT2TY]] [[STRUCT2IN2]], [[STRUCT1TY]] [[STRUCTIN7]], 1 205; CHECK-NEXT: [[RET0:%.*]] = insertvalue { [[STRUCT2TY]], [[STRUCT2TY]] } undef, [[STRUCT2TY]] [[STRUCT2IN1]], 0 206; CHECK-NEXT: [[RET1:%.*]] = insertvalue { [[STRUCT2TY]], [[STRUCT2TY]] } [[RET0]], [[STRUCT2TY]] [[STRUCT2IN3]], 1 207; CHECK-NEXT: ret { [[STRUCT2TY]], [[STRUCT2TY]] } [[RET1]] 208; 209 %GEP0 = getelementptr inbounds i16, i16* %Ptr, i64 0 210 %L0 = load i16, i16 * %GEP0 211 %GEP1 = getelementptr inbounds i16, i16* %Ptr, i64 1 212 %L1 = load i16, i16 * %GEP1 213 %GEP2 = getelementptr inbounds i16, i16* %Ptr, i64 2 214 %L2 = load i16, i16 * %GEP2 215 %GEP3 = getelementptr inbounds i16, i16* %Ptr, i64 3 216 %L3 = load i16, i16 * %GEP3 217 %GEP4 = getelementptr inbounds i16, i16* %Ptr, i64 4 218 %L4 = load i16, i16 * %GEP4 219 %GEP5 = getelementptr inbounds i16, i16* %Ptr, i64 5 220 %L5 = load i16, i16 * %GEP5 221 %GEP6 = getelementptr inbounds i16, i16* %Ptr, i64 6 222 %L6 = load i16, i16 * %GEP6 223 %GEP7 = getelementptr inbounds i16, i16* %Ptr, i64 7 224 %L7 = load i16, i16 * %GEP7 225 226 %Fadd0 = add i16 %L0, 1 227 %Fadd1 = add i16 %L1, 2 228 %Fadd2 = add i16 %L2, 3 229 %Fadd3 = add i16 %L3, 4 230 %Fadd4 = add i16 %L4, 5 231 %Fadd5 = add i16 %L5, 6 232 %Fadd6 = add i16 %L6, 7 233 %Fadd7 = add i16 %L7, 8 234 235 %StructIn0 = insertvalue %Struct1Ty undef, i16 %Fadd0, 0 236 %StructIn1 = insertvalue %Struct1Ty %StructIn0, i16 %Fadd1, 1 237 238 %StructIn2 = insertvalue %Struct1Ty undef, i16 %Fadd2, 0 239 %StructIn3 = insertvalue %Struct1Ty %StructIn2, i16 %Fadd3, 1 240 241 %StructIn4 = insertvalue %Struct1Ty undef, i16 %Fadd4, 0 242 %StructIn5 = insertvalue %Struct1Ty %StructIn4, i16 %Fadd5, 1 243 244 %StructIn6 = insertvalue %Struct1Ty undef, i16 %Fadd6, 0 245 %StructIn7 = insertvalue %Struct1Ty %StructIn6, i16 %Fadd7, 1 246 247 %Struct2In0 = insertvalue %Struct2Ty undef, %Struct1Ty %StructIn1, 0 248 %Struct2In1 = insertvalue %Struct2Ty %Struct2In0, %Struct1Ty %StructIn3, 1 249 250 %Struct2In2 = insertvalue %Struct2Ty undef, %Struct1Ty %StructIn5, 0 251 %Struct2In3 = insertvalue %Struct2Ty %Struct2In2, %Struct1Ty %StructIn7, 1 252 253 %Ret0 = insertvalue {%Struct2Ty, %Struct2Ty} undef, %Struct2Ty %Struct2In1, 0 254 %Ret1 = insertvalue {%Struct2Ty, %Struct2Ty} %Ret0, %Struct2Ty %Struct2In3, 1 255 ret {%Struct2Ty, %Struct2Ty} %Ret1 256} 257