summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2016-09-23 09:14:08 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2016-09-23 09:14:08 +0000
commitfee9078dcd77a067eaad1a5f59f9529faca4376b (patch)
treee352ad1165d46aef65f526728f1bcea4288c2989 /llvm/test/Transforms/InstCombine
parent0f8f0d369d719cf3cb785e294463722f94d05cc0 (diff)
downloadbcm5719-llvm-fee9078dcd77a067eaad1a5f59f9529faca4376b.tar.gz
bcm5719-llvm-fee9078dcd77a067eaad1a5f59f9529faca4376b.zip
[InstCombine] Fix for PR29124: reduce insertelements to shufflevector
If inserting more than one constant into a vector: define <4 x float> @foo(<4 x float> %x) { %ins1 = insertelement <4 x float> %x, float 1.0, i32 1 %ins2 = insertelement <4 x float> %ins1, float 2.0, i32 2 ret <4 x float> %ins2 } InstCombine could reduce that to a shufflevector: define <4 x float> @goo(<4 x float> %x) { %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> ret <4 x float> %shuf } Also, InstCombine tries to convert shuffle instruction to single insertelement, if one of the vectors is a constant vector and only a single element from this constant should be used in shuffle, i.e. shufflevector <4 x float> %v, <4 x float> <float undef, float 1.0, float undef, float undef>, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef> -> insertelement <4 x float> %v, float 1.0, 1 Differential Revision: https://reviews.llvm.org/D24182 llvm-svn: 282237
Diffstat (limited to 'llvm/test/Transforms/InstCombine')
-rw-r--r--llvm/test/Transforms/InstCombine/insert-const-shuf.ll9
-rw-r--r--llvm/test/Transforms/InstCombine/vec_demanded_elts.ll4
-rw-r--r--llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll29
-rw-r--r--llvm/test/Transforms/InstCombine/x86-insertps.ll2
4 files changed, 35 insertions, 9 deletions
diff --git a/llvm/test/Transforms/InstCombine/insert-const-shuf.ll b/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
index 60f272f1096..3e301e336af 100644
--- a/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
+++ b/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
@@ -26,6 +26,15 @@ define <4 x float> @twoInserts(<4 x float> %x) {
ret <4 x float> %ins2
}
+define <4 x i32> @shuffleRetain(<4 x i32> %base) {
+; CHECK-LABEL: @shuffleRetain(
+; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> %base, <4 x i32> <i32 undef, i32 undef, i32 undef, i32 1>, <4 x i32> <i32 1, i32 2, i32 undef, i32 7>
+; CHECK-NEXT: ret <4 x i32> [[SHUF]]
+;
+ %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>
+ ret <4 x i32> %shuf
+}
+
; 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) {
diff --git a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
index 604806e20a8..2ee30d771e1 100644
--- a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
+++ b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
@@ -236,8 +236,8 @@ define <4 x float> @test_select(float %f, float %g) {
define <2 x i64> @PR24922(<2 x i64> %v) {
; CHECK-LABEL: @PR24922(
-; CHECK-NEXT: [[RESULT:%.*]] = shufflevector <2 x i64> %v, <2 x i64> <i64 0, i64 undef>, <2 x i32> <i32 2, i32 1>
-; CHECK-NEXT: ret <2 x i64> [[RESULT]]
+; CHECK-NEXT: [[RESULT1:%.*]] = insertelement <2 x i64> %v, i64 0, i32 0
+; CHECK-NEXT: ret <2 x i64> [[RESULT1]]
;
%result = select <2 x i1> <i1 icmp eq (i64 extractelement (<2 x i64> bitcast (<4 x i32> <i32 15, i32 15, i32 15, i32 15> to <2 x i64>), i64 0), i64 0), i1 true>, <2 x i64> %v, <2 x i64> zeroinitializer
ret <2 x i64> %result
diff --git a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
index 9b45962569a..b3e614653cf 100644
--- a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
@@ -7,10 +7,9 @@ define<4 x float> @foo(<4 x float> %x) {
ret<4 x float> %ins2
}
-; FIXME: insertelements should fold to shuffle
+; insertelements should fold to shuffle
; CHECK-LABEL: @foo
-; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 1.000000e+00, i32 1
-; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 2.000000e+00, i32 2
+; CHECK-NEXT: shufflevector <4 x float> %{{.+}}, <4 x float> <float undef, float 1.000000e+00, float 2.000000e+00, float undef>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
; CHECK-NEXT: ret <4 x float> %
define<4 x float> @bar(<4 x float> %x, float %a) {
@@ -45,12 +44,11 @@ define<4 x float> @bazz(<4 x float> %x, i32 %a) {
ret<4 x float> %ins6
}
-; FIXME: insertelements should fold to shuffle
+; insertelements should fold to shuffle
; CHECK-LABEL: @bazz
; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 1.000000e+00, i32 3
; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 5.000000e+00, i32 %
-; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 1.000000e+00, i32 1
-; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 2.000000e+00, i32 2
+; CHECK-NEXT: shufflevector <4 x float> %{{.+}}, <4 x float> <float undef, float 1.000000e+00, float 2.000000e+00, float undef>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 7.000000e+00, i32 %
; CHECK-NEXT: ret <4 x float> %
@@ -75,3 +73,22 @@ define<4 x float> @bazzzz(<4 x float> %x) {
; CHECK-NEXT: insertelement <4 x float> %{{.+}}, float 2.000000e+00, i32 2
; CHECK-NEXT: ret <4 x float> %
+define<4 x float> @bazzzzz() {
+ %ins1 = insertelement <4 x float> insertelement (<4 x float> <float 1.0, float 2.0, float 3.0, float undef>, float 4.0, i32 3), float 5.0, i32 1
+ %ins2 = insertelement<4 x float> %ins1, float 10.0, i32 2
+ ret<4 x float> %ins2
+}
+
+; insertelements should fold to shuffle
+; CHECK-LABEL: @bazzzzz
+; CHECK-NEXT: ret <4 x float> <float 1.000000e+00, float 5.000000e+00, float 1.000000e+01, float 4.000000e+00>
+
+define<4 x float> @bazzzzzz(<4 x float> %x, i32 %a) {
+ %ins1 = insertelement <4 x float> insertelement (<4 x float> shufflevector (<4 x float> undef, <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0> , <4 x i32> <i32 0, i32 5, i32 undef, i32 6> ), float 4.0, i32 3), float 5.0, i32 1
+ ret<4 x float> %ins1
+}
+
+; insertelements should fold to shuffle
+; CHECK-LABEL: @bazzzzz
+; CHECK-NEXT: ret <4 x float> <float undef, float 5.000000e+00, float undef, float 4.000000e+00>
+
diff --git a/llvm/test/Transforms/InstCombine/x86-insertps.ll b/llvm/test/Transforms/InstCombine/x86-insertps.ll
index bb1a3f369a3..f55ea6f22d2 100644
--- a/llvm/test/Transforms/InstCombine/x86-insertps.ll
+++ b/llvm/test/Transforms/InstCombine/x86-insertps.ll
@@ -74,7 +74,7 @@ define <4 x float> @insertps_0x1a_single_input(<4 x float> %v1) {
define <4 x float> @insertps_0xc1(<4 x float> %v1, <4 x float> %v2) {
; CHECK-LABEL: @insertps_0xc1(
-; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> <float 0.000000e+00, float undef, float undef, float undef>, <4 x i32> <i32 4, i32 1, i32 2, i32 3>
+; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> %v1, float 0.000000e+00, i32 0
; CHECK-NEXT: ret <4 x float> [[TMP1]]
;
%res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 193)
OpenPOWER on IntegriCloud