Skip to content

Commit 65f1c04

Browse files
committed
[InstCombine] reduce duplicated code; NFC
llvm-svn: 370399
1 parent f9f8128 commit 65f1c04

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,26 +2391,29 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
23912391
}
23922392
}
23932393

2394-
if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(Src)) {
2394+
if (auto *Shuf = dyn_cast<ShuffleVectorInst>(Src)) {
23952395
// Okay, we have (bitcast (shuffle ..)). Check to see if this is
23962396
// a bitcast to a vector with the same # elts.
2397-
if (SVI->hasOneUse() && DestTy->isVectorTy() &&
2398-
DestTy->getVectorNumElements() == SVI->getType()->getNumElements() &&
2399-
SVI->getType()->getNumElements() ==
2400-
SVI->getOperand(0)->getType()->getVectorNumElements()) {
2397+
Value *ShufOp0 = Shuf->getOperand(0);
2398+
Value *ShufOp1 = Shuf->getOperand(1);
2399+
unsigned NumShufElts = Shuf->getType()->getVectorNumElements();
2400+
unsigned NumSrcVecElts = ShufOp0->getType()->getVectorNumElements();
2401+
if (Shuf->hasOneUse() && DestTy->isVectorTy() &&
2402+
DestTy->getVectorNumElements() == NumShufElts &&
2403+
NumShufElts == NumSrcVecElts) {
24012404
BitCastInst *Tmp;
24022405
// If either of the operands is a cast from CI.getType(), then
24032406
// evaluating the shuffle in the casted destination's type will allow
24042407
// us to eliminate at least one cast.
2405-
if (((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(0))) &&
2408+
if (((Tmp = dyn_cast<BitCastInst>(ShufOp0)) &&
24062409
Tmp->getOperand(0)->getType() == DestTy) ||
2407-
((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(1))) &&
2410+
((Tmp = dyn_cast<BitCastInst>(ShufOp1)) &&
24082411
Tmp->getOperand(0)->getType() == DestTy)) {
2409-
Value *LHS = Builder.CreateBitCast(SVI->getOperand(0), DestTy);
2410-
Value *RHS = Builder.CreateBitCast(SVI->getOperand(1), DestTy);
2412+
Value *LHS = Builder.CreateBitCast(ShufOp0, DestTy);
2413+
Value *RHS = Builder.CreateBitCast(ShufOp1, DestTy);
24112414
// Return a new shuffle vector. Use the same element ID's, as we
24122415
// know the vector types match #elts.
2413-
return new ShuffleVectorInst(LHS, RHS, SVI->getOperand(2));
2416+
return new ShuffleVectorInst(LHS, RHS, Shuf->getOperand(2));
24142417
}
24152418
}
24162419
}

0 commit comments

Comments
 (0)