119 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes=instcombine %s | FileCheck %s3 4; Eliminate the insertelement.5 6define <4 x float> @PR29126(<4 x float> %x) {7; CHECK-LABEL: @PR29126(8; CHECK-NEXT: [[INS:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float 1.000000e+00, float 2.000000e+00, float 4.200000e+01>, <4 x i32> <i32 0, i32 5, i32 6, i32 7>9; CHECK-NEXT: ret <4 x float> [[INS]]10;11 %shuf = shufflevector <4 x float> %x, <4 x float> <float undef, float 1.0, float 2.0, float undef>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>12 %ins = insertelement <4 x float> %shuf, float 42.0, i32 313 ret <4 x float> %ins14}15 16; A chain of inserts should collapse.17 18define <4 x float> @twoInserts(<4 x float> %x) {19; CHECK-LABEL: @twoInserts(20; CHECK-NEXT: [[INS2:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float 0.000000e+00, float 4.200000e+01, float 1.100000e+01>, <4 x i32> <i32 0, i32 5, i32 6, i32 7>21; CHECK-NEXT: ret <4 x float> [[INS2]]22;23 %shuf = shufflevector <4 x float> %x, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 5, i32 6, i32 3>24 %ins1 = insertelement <4 x float> %shuf, float 42.0, i32 225 %ins2 = insertelement <4 x float> %ins1, float 11.0, i32 326 ret <4 x float> %ins227}28 29define <4 x i32> @shuffleRetain(<4 x i32> %base) {30; CHECK-LABEL: @shuffleRetain(31; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[BASE:%.*]], <4 x i32> <i32 poison, i32 poison, i32 poison, i32 1>, <4 x i32> <i32 1, i32 2, i32 poison, i32 7>32; CHECK-NEXT: ret <4 x i32> [[SHUF]]33;34 %shuf = shufflevector <4 x i32> %base, <4 x i32> <i32 4, i32 3, i32 2, i32 1>, <4 x i32> <i32 1, i32 2, i32 undef, i32 7>35 ret <4 x i32> %shuf36}37 38; TODO: Transform an arbitrary shuffle with constant into a shuffle that is equivalant to a vector select.39 40define <4 x float> @disguisedSelect(<4 x float> %x) {41; CHECK-LABEL: @disguisedSelect(42; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float 1.000000e+00, float 2.000000e+00, float poison>, <4 x i32> <i32 poison, i32 6, i32 5, i32 3>43; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i64 044; CHECK-NEXT: ret <4 x float> [[INS]]45;46 %shuf = shufflevector <4 x float> %x, <4 x float> <float undef, float 1.0, float 2.0, float 3.0>, <4 x i32> <i32 7, i32 6, i32 5, i32 3>47 %ins = insertelement <4 x float> %shuf, float 4.0, i32 048 ret <4 x float> %ins49}50 51; TODO: Fold arbitrary (non-select-equivalent) shuffles if the new shuffle would have the same shuffle mask.52 53define <4 x float> @notSelectButNoMaskDifference(<4 x float> %x) {54; CHECK-LABEL: @notSelectButNoMaskDifference(55; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float 1.000000e+00, float 2.000000e+00, float poison>, <4 x i32> <i32 1, i32 5, i32 6, i32 poison>56; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i64 357; CHECK-NEXT: ret <4 x float> [[INS]]58;59 %shuf = shufflevector <4 x float> %x, <4 x float> <float undef, float 1.0, float 2.0, float 3.0>, <4 x i32> <i32 1, i32 5, i32 6, i32 3>60 %ins = insertelement <4 x float> %shuf, float 4.0, i32 361 ret <4 x float> %ins62}63 64; We purposely do not touch arbitrary (non-select-equivalent) shuffles because folding the insert may create a more expensive shuffle.65 66define <4 x float> @tooRisky(<4 x float> %x) {67; CHECK-LABEL: @tooRisky(68; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float 1.000000e+00, float poison, float poison, float poison>, <4 x i32> <i32 1, i32 4, i32 4, i32 poison>69; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i64 370; CHECK-NEXT: ret <4 x float> [[INS]]71;72 %shuf = shufflevector <4 x float> %x, <4 x float> <float 1.0, float undef, float undef, float undef>, <4 x i32> <i32 1, i32 4, i32 4, i32 4>73 %ins = insertelement <4 x float> %shuf, float 4.0, i32 374 ret <4 x float> %ins75}76 77; Don't transform insert to shuffle if the original shuffle is not removed.78; TODO: Ease the one-use restriction if the insert scalar would simplify the shuffle to a full vector constant?79 80define <3 x float> @twoShufUses(<3 x float> %x) {81; CHECK-LABEL: @twoShufUses(82; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x float> [[X:%.*]], <3 x float> <float poison, float 1.000000e+00, float 2.000000e+00>, <3 x i32> <i32 0, i32 4, i32 5>83; CHECK-NEXT: [[INS:%.*]] = insertelement <3 x float> [[SHUF]], float 4.200000e+01, i64 184; CHECK-NEXT: [[ADD:%.*]] = fadd <3 x float> [[SHUF]], [[INS]]85; CHECK-NEXT: ret <3 x float> [[ADD]]86;87 %shuf = shufflevector <3 x float> %x, <3 x float> <float undef, float 1.0, float 2.0>, <3 x i32> <i32 0, i32 4, i32 5>88 %ins = insertelement <3 x float> %shuf, float 42.0, i2 189 %add = fadd <3 x float> %shuf, %ins90 ret <3 x float> %add91}92 93; The inserted scalar constant index is out-of-bounds for the shuffle vector constant.94 95define <5 x i8> @longerMask(<3 x i8> %x) {96; CHECK-LABEL: @longerMask(97; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> <i8 undef, i8 1, i8 poison>, <5 x i32> <i32 2, i32 1, i32 4, i32 3, i32 poison>98; CHECK-NEXT: [[INS:%.*]] = insertelement <5 x i8> [[SHUF]], i8 42, i64 499; CHECK-NEXT: ret <5 x i8> [[INS]]100;101 %shuf = shufflevector <3 x i8> %x, <3 x i8> <i8 undef, i8 1, i8 2>, <5 x i32> <i32 2, i32 1, i32 4, i32 3, i32 0>102 %ins = insertelement <5 x i8> %shuf, i8 42, i17 4103 ret <5 x i8> %ins104}105 106; TODO: The inserted constant could get folded into the shuffle vector constant.107 108define <3 x i8> @shorterMask(<5 x i8> %x) {109; CHECK-LABEL: @shorterMask(110; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <5 x i8> [[X:%.*]], <5 x i8> poison, <3 x i32> <i32 poison, i32 1, i32 4>111; CHECK-NEXT: [[INS:%.*]] = insertelement <3 x i8> [[SHUF]], i8 42, i64 0112; CHECK-NEXT: ret <3 x i8> [[INS]]113;114 %shuf = shufflevector <5 x i8> %x, <5 x i8> <i8 undef, i8 1, i8 2, i8 3, i8 4>, <3 x i32> <i32 2, i32 1, i32 4>115 %ins = insertelement <3 x i8> %shuf, i8 42, i21 0116 ret <3 x i8> %ins117}118 119