diff options
author | Chris Lattner <sabre@nondot.org> | 2007-01-05 07:36:08 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-01-05 07:36:08 +0000 |
commit | e4929dd0cc7f192028082cf6a17119567119fdf2 (patch) | |
tree | 429b4c64f8f2434db7791c02a06c7a9eca5e4853 | |
parent | 4e56f7c81c321e458db0ce441b0f93d0b063e0ef (diff) | |
download | external_llvm-e4929dd0cc7f192028082cf6a17119567119fdf2.zip external_llvm-e4929dd0cc7f192028082cf6a17119567119fdf2.tar.gz external_llvm-e4929dd0cc7f192028082cf6a17119567119fdf2.tar.bz2 |
Implement InstCombine/vec_shuffle.ll:%test7, simplifying shuffles with
undef operands.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32899 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index c1a331f..eaab4c6 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8833,8 +8833,30 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (isa<UndefValue>(SVI.getOperand(2))) return ReplaceInstUsesWith(SVI, UndefValue::get(SVI.getType())); - // TODO: If we have shuffle(x, undef, mask) and any elements of mask refer to + // If we have shuffle(x, undef, mask) and any elements of mask refer to // the undef, change them to undefs. + if (isa<UndefValue>(SVI.getOperand(1))) { + // Scan to see if there are any references to the RHS. If so, replace them + // with undef element refs and set MadeChange to true. + for (unsigned i = 0, e = Mask.size(); i != e; ++i) { + if (Mask[i] >= e && Mask[i] != 2*e) { + Mask[i] = 2*e; + MadeChange = true; + } + } + + if (MadeChange) { + // Remap any references to RHS to use LHS. + std::vector<Constant*> Elts; + for (unsigned i = 0, e = Mask.size(); i != e; ++i) { + if (Mask[i] == 2*e) + Elts.push_back(UndefValue::get(Type::Int32Ty)); + else + Elts.push_back(ConstantInt::get(Type::Int32Ty, Mask[i])); + } + SVI.setOperand(2, ConstantPacked::get(Elts)); + } + } // Canonicalize shuffle(x ,x,mask) -> shuffle(x, undef,mask') // Canonicalize shuffle(undef,x,mask) -> shuffle(x, undef,mask'). |