diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-04-16 00:03:56 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-04-16 00:03:56 +0000 |
| commit | 34cebe785d74b7af76a0be77bff075b2320f8cb0 (patch) | |
| tree | c0f3551ebf696efdec44c48df07e268d319273eb /llvm/lib/Transforms | |
| parent | 24acbe46c0c63c2b91ceebc7c24165a268287a1f (diff) | |
| download | bcm5719-llvm-34cebe785d74b7af76a0be77bff075b2320f8cb0.tar.gz bcm5719-llvm-34cebe785d74b7af76a0be77bff075b2320f8cb0.zip | |
Canonicalize shuffle(undef,x,mask) -> shuffle(x, undef,mask').
llvm-svn: 27727
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index a502bd25fef..7d1ddbf0983 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7046,8 +7046,6 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (isa<UndefValue>(Mask)) return ReplaceInstUsesWith(SVI, UndefValue::get(SVI.getType())); - // TODO: Canonicalize shuffle(undef,x) -> shuffle(x, undef). - // TODO: If we have shuffle(x, undef, mask) and any elements of mask refer to // the undef, change them to undefs. @@ -7077,6 +7075,28 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { MadeChange = true; } + // Canonicalize shuffle(undef,x,mask) -> shuffle(x, undef,mask'). + if (isa<UndefValue>(LHS)) { + // shuffle(undef,x,<0,0,0,0>) -> undef. + if (isa<ConstantAggregateZero>(Mask)) + return ReplaceInstUsesWith(SVI, UndefValue::get(SVI.getType())); + + ConstantPacked *CPM = cast<ConstantPacked>(Mask); + std::vector<Constant*> Elts; + for (unsigned i = 0, e = CPM->getNumOperands(); i != e; ++i) { + if (isa<UndefValue>(CPM->getOperand(i))) + Elts.push_back(CPM->getOperand(i)); + else { + unsigned EltNo = cast<ConstantUInt>(CPM->getOperand(i))->getRawValue(); + if (EltNo >= e/2) + Elts.push_back(ConstantUInt::get(Type::UIntTy, EltNo-e/2)); + else // Referring to the undef. + Elts.push_back(UndefValue::get(Type::UIntTy)); + } + } + return new ShuffleVectorInst(RHS, LHS, ConstantPacked::get(Elts)); + } + if (ConstantPacked *CP = dyn_cast<ConstantPacked>(Mask)) { bool isLHSID = true, isRHSID = true; |

