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 | 706126dac165785b5d5bb15157b48094733ee7f3 (patch) | |
tree | 624212f43d448a366b44662893d34303bbf577f9 | |
parent | 730b45694bd910efe0c5c38897854222f74c92bb (diff) |
Canonicalize shuffle(undef,x,mask) -> shuffle(x, undef,mask').
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27727 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index a502bd25fe..7d1ddbf098 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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; |