@@ -2391,26 +2391,29 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
2391
2391
}
2392
2392
}
2393
2393
2394
- if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(Src)) {
2394
+ if (auto *Shuf = dyn_cast<ShuffleVectorInst>(Src)) {
2395
2395
// Okay, we have (bitcast (shuffle ..)). Check to see if this is
2396
2396
// 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) {
2401
2404
BitCastInst *Tmp;
2402
2405
// If either of the operands is a cast from CI.getType(), then
2403
2406
// evaluating the shuffle in the casted destination's type will allow
2404
2407
// us to eliminate at least one cast.
2405
- if (((Tmp = dyn_cast<BitCastInst>(SVI-> getOperand ( 0 ) )) &&
2408
+ if (((Tmp = dyn_cast<BitCastInst>(ShufOp0 )) &&
2406
2409
Tmp->getOperand (0 )->getType () == DestTy) ||
2407
- ((Tmp = dyn_cast<BitCastInst>(SVI-> getOperand ( 1 ) )) &&
2410
+ ((Tmp = dyn_cast<BitCastInst>(ShufOp1 )) &&
2408
2411
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);
2411
2414
// Return a new shuffle vector. Use the same element ID's, as we
2412
2415
// know the vector types match #elts.
2413
- return new ShuffleVectorInst (LHS, RHS, SVI ->getOperand (2 ));
2416
+ return new ShuffleVectorInst (LHS, RHS, Shuf ->getOperand (2 ));
2414
2417
}
2415
2418
}
2416
2419
}
0 commit comments