[InstCombine] Fix for PR29124: reduce insertelements to shufflevector
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 23 Sep 2016 09:14:08 +0000 (09:14 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 23 Sep 2016 09:14:08 +0000 (09:14 +0000)
commitfee9078dcd77a067eaad1a5f59f9529faca4376b
treee352ad1165d46aef65f526728f1bcea4288c2989
parent0f8f0d369d719cf3cb785e294463722f94d05cc0
[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
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/insert-const-shuf.ll
llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
llvm/test/Transforms/InstCombine/x86-insertps.ll