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 | d7b6ea166dfcf6fc39e953a9b81bf84d6927053e (patch) | |
| tree | 15a007a828713731ad68e97d18ede81ecaf618c0 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
| parent | e4f7c5cf35010de13a0fa404165cb939378e002d (diff) | |
| download | bcm5719-llvm-d7b6ea166dfcf6fc39e953a9b81bf84d6927053e.tar.gz bcm5719-llvm-d7b6ea166dfcf6fc39e953a9b81bf84d6927053e.zip | |
Implement InstCombine/vec_shuffle.ll:%test7, simplifying shuffles with
undef operands.
llvm-svn: 32899
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index c1a331faecb..eaab4c6b9c5 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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'). |

