forked from OSchip/llvm-project
[InstCombine] reduce duplicated code; NFC
llvm-svn: 370399
This commit is contained in:
parent
f9f81289e6
commit
65f1c04000
|
@ -2391,26 +2391,29 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(Src)) {
|
if (auto *Shuf = dyn_cast<ShuffleVectorInst>(Src)) {
|
||||||
// Okay, we have (bitcast (shuffle ..)). Check to see if this is
|
// Okay, we have (bitcast (shuffle ..)). Check to see if this is
|
||||||
// a bitcast to a vector with the same # elts.
|
// a bitcast to a vector with the same # elts.
|
||||||
if (SVI->hasOneUse() && DestTy->isVectorTy() &&
|
Value *ShufOp0 = Shuf->getOperand(0);
|
||||||
DestTy->getVectorNumElements() == SVI->getType()->getNumElements() &&
|
Value *ShufOp1 = Shuf->getOperand(1);
|
||||||
SVI->getType()->getNumElements() ==
|
unsigned NumShufElts = Shuf->getType()->getVectorNumElements();
|
||||||
SVI->getOperand(0)->getType()->getVectorNumElements()) {
|
unsigned NumSrcVecElts = ShufOp0->getType()->getVectorNumElements();
|
||||||
|
if (Shuf->hasOneUse() && DestTy->isVectorTy() &&
|
||||||
|
DestTy->getVectorNumElements() == NumShufElts &&
|
||||||
|
NumShufElts == NumSrcVecElts) {
|
||||||
BitCastInst *Tmp;
|
BitCastInst *Tmp;
|
||||||
// If either of the operands is a cast from CI.getType(), then
|
// If either of the operands is a cast from CI.getType(), then
|
||||||
// evaluating the shuffle in the casted destination's type will allow
|
// evaluating the shuffle in the casted destination's type will allow
|
||||||
// us to eliminate at least one cast.
|
// us to eliminate at least one cast.
|
||||||
if (((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(0))) &&
|
if (((Tmp = dyn_cast<BitCastInst>(ShufOp0)) &&
|
||||||
Tmp->getOperand(0)->getType() == DestTy) ||
|
Tmp->getOperand(0)->getType() == DestTy) ||
|
||||||
((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(1))) &&
|
((Tmp = dyn_cast<BitCastInst>(ShufOp1)) &&
|
||||||
Tmp->getOperand(0)->getType() == DestTy)) {
|
Tmp->getOperand(0)->getType() == DestTy)) {
|
||||||
Value *LHS = Builder.CreateBitCast(SVI->getOperand(0), DestTy);
|
Value *LHS = Builder.CreateBitCast(ShufOp0, DestTy);
|
||||||
Value *RHS = Builder.CreateBitCast(SVI->getOperand(1), DestTy);
|
Value *RHS = Builder.CreateBitCast(ShufOp1, DestTy);
|
||||||
// Return a new shuffle vector. Use the same element ID's, as we
|
// Return a new shuffle vector. Use the same element ID's, as we
|
||||||
// know the vector types match #elts.
|
// know the vector types match #elts.
|
||||||
return new ShuffleVectorInst(LHS, RHS, SVI->getOperand(2));
|
return new ShuffleVectorInst(LHS, RHS, Shuf->getOperand(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue