Fix an expensive-checks error.

The Mask and LHSMask may not be of the same size, so don't do the
transformation if they're different.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@88972 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Greene
2009-11-16 21:52:23 +00:00
parent 7bde297133
commit f941d29077

View File

@@ -12917,6 +12917,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
if (isa<UndefValue>(RHS)) { if (isa<UndefValue>(RHS)) {
std::vector<unsigned> LHSMask = getShuffleMask(LHSSVI); std::vector<unsigned> LHSMask = getShuffleMask(LHSSVI);
if (LHSMask.size() == Mask.size()) {
std::vector<unsigned> NewMask; std::vector<unsigned> NewMask;
for (unsigned i = 0, e = Mask.size(); i != e; ++i) for (unsigned i = 0, e = Mask.size(); i != e; ++i)
if (Mask[i] >= 2*e) if (Mask[i] >= 2*e)
@@ -12924,17 +12925,19 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
else else
NewMask.push_back(LHSMask[Mask[i]]); NewMask.push_back(LHSMask[Mask[i]]);
// If the result mask is equal to the src shuffle or this shuffle mask, do // If the result mask is equal to the src shuffle or this
// the replacement. // shuffle mask, do the replacement.
if (NewMask == LHSMask || NewMask == Mask) { if (NewMask == LHSMask || NewMask == Mask) {
unsigned LHSInNElts = unsigned LHSInNElts =
cast<VectorType>(LHSSVI->getOperand(0)->getType())->getNumElements(); cast<VectorType>(LHSSVI->getOperand(0)->getType())->
getNumElements();
std::vector<Constant*> Elts; std::vector<Constant*> Elts;
for (unsigned i = 0, e = NewMask.size(); i != e; ++i) { for (unsigned i = 0, e = NewMask.size(); i != e; ++i) {
if (NewMask[i] >= LHSInNElts*2) { if (NewMask[i] >= LHSInNElts*2) {
Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context))); Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context)));
} else { } else {
Elts.push_back(ConstantInt::get(Type::getInt32Ty(*Context), NewMask[i])); Elts.push_back(ConstantInt::get(Type::getInt32Ty(*Context),
NewMask[i]));
} }
} }
return new ShuffleVectorInst(LHSSVI->getOperand(0), return new ShuffleVectorInst(LHSSVI->getOperand(0),
@@ -12943,6 +12946,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
} }
} }
} }
}
return MadeChange ? &SVI : 0; return MadeChange ? &SVI : 0;
} }