From: Sanjay Patel Date: Thu, 1 Sep 2016 19:14:19 +0000 (+0000) Subject: [InstCombine] add tests to show potential shuffle+insert folds X-Git-Tag: android-x86-7.1-r4~27720 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=78e359ca5bd865c19e6b632c14ce02f4828c29b4;p=android-x86%2Fexternal-llvm.git [InstCombine] add tests to show potential shuffle+insert folds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/insert-const-shuf.ll b/test/Transforms/InstCombine/insert-const-shuf.ll new file mode 100644 index 00000000000..ebdf428f1a4 --- /dev/null +++ b/test/Transforms/InstCombine/insert-const-shuf.ll @@ -0,0 +1,112 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -instcombine %s | FileCheck %s + +; TODO: Eliminate the insertelement. + +define <4 x float> @PR29126(<4 x float> %x) { +; CHECK-LABEL: @PR29126( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> %x, <4 x float> , <4 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.200000e+01, i32 3 +; CHECK-NEXT: ret <4 x float> [[INS]] +; + %shuf = shufflevector <4 x float> %x, <4 x float> , <4 x i32> + %ins = insertelement <4 x float> %shuf, float 42.0, i32 3 + ret <4 x float> %ins +} + +; TODO: A chain of inserts should collapse. + +define <4 x float> @twoInserts(<4 x float> %x) { +; CHECK-LABEL: @twoInserts( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> %x, <4 x float> , <4 x i32> +; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> [[SHUF]], float 4.200000e+01, i32 2 +; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float 1.100000e+01, i32 3 +; CHECK-NEXT: ret <4 x float> [[INS2]] +; + %shuf = shufflevector <4 x float> %x, <4 x float> zeroinitializer, <4 x i32> + %ins1 = insertelement <4 x float> %shuf, float 42.0, i32 2 + %ins2 = insertelement <4 x float> %ins1, float 11.0, i32 3 + ret <4 x float> %ins2 +} + +; TODO: Transform an arbitrary shuffle with constant into a shuffle that is equivalant to a vector select. + +define <4 x float> @disguisedSelect(<4 x float> %x) { +; CHECK-LABEL: @disguisedSelect( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> %x, <4 x float> , <4 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i32 0 +; CHECK-NEXT: ret <4 x float> [[INS]] +; + %shuf = shufflevector <4 x float> %x, <4 x float> , <4 x i32> + %ins = insertelement <4 x float> %shuf, float 4.0, i32 0 + ret <4 x float> %ins +} + +; TODO: Fold arbitrary (non-select-equivalent) shuffles if the new shuffle would have the same shuffle mask. + +define <4 x float> @notSelectButNoMaskDifference(<4 x float> %x) { +; CHECK-LABEL: @notSelectButNoMaskDifference( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> %x, <4 x float> , <4 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i32 3 +; CHECK-NEXT: ret <4 x float> [[INS]] +; + %shuf = shufflevector <4 x float> %x, <4 x float> , <4 x i32> + %ins = insertelement <4 x float> %shuf, float 4.0, i32 3 + ret <4 x float> %ins +} + +; We purposely do not touch arbitrary (non-select-equivalent) shuffles because folding the insert may create a more expensive shuffle. + +define <4 x float> @tooRisky(<4 x float> %x) { +; CHECK-LABEL: @tooRisky( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> %x, <4 x float> , <4 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[SHUF]], float 4.000000e+00, i32 3 +; CHECK-NEXT: ret <4 x float> [[INS]] +; + %shuf = shufflevector <4 x float> %x, <4 x float> , <4 x i32> + %ins = insertelement <4 x float> %shuf, float 4.0, i32 3 + ret <4 x float> %ins +} + +; Don't transform insert to shuffle if the original shuffle is not removed. +; TODO: Ease the one-use restriction if the insert scalar would simplify the shuffle to a full vector constant? + +define <3 x float> @twoShufUses(<3 x float> %x) { +; CHECK-LABEL: @twoShufUses( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x float> %x, <3 x float> , <3 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <3 x float> [[SHUF]], float 4.200000e+01, i2 1 +; CHECK-NEXT: [[ADD:%.*]] = fadd <3 x float> [[SHUF]], [[INS]] +; CHECK-NEXT: ret <3 x float> [[ADD]] +; + %shuf = shufflevector <3 x float> %x, <3 x float> , <3 x i32> + %ins = insertelement <3 x float> %shuf, float 42.0, i2 1 + %add = fadd <3 x float> %shuf, %ins + ret <3 x float> %add +} + +; The inserted scalar constant index is out-of-bounds for the shuffle vector constant. + +define <5 x i8> @longerMask(<3 x i8> %x) { +; CHECK-LABEL: @longerMask( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i8> %x, <3 x i8> , <5 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <5 x i8> [[SHUF]], i8 42, i17 4 +; CHECK-NEXT: ret <5 x i8> [[INS]] +; + %shuf = shufflevector <3 x i8> %x, <3 x i8> , <5 x i32> + %ins = insertelement <5 x i8> %shuf, i8 42, i17 4 + ret <5 x i8> %ins +} + +; TODO: The inserted constant could get folded into the shuffle vector constant. + +define <3 x i8> @shorterMask(<5 x i8> %x) { +; CHECK-LABEL: @shorterMask( +; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <5 x i8> %x, <5 x i8> undef, <3 x i32> +; CHECK-NEXT: [[INS:%.*]] = insertelement <3 x i8> [[SHUF]], i8 42, i21 0 +; CHECK-NEXT: ret <3 x i8> [[INS]] +; + %shuf = shufflevector <5 x i8> %x, <5 x i8> , <3 x i32> + %ins = insertelement <3 x i8> %shuf, i8 42, i21 0 + ret <3 x i8> %ins +} +