@@ -683,25 +683,27 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
683
683
return FoldedShift;
684
684
685
685
// Fold shift2(trunc(shift1(x,c1)), c2) -> trunc(shift2(shift1(x,c1),c2))
686
- if (TruncInst *TI = dyn_cast<TruncInst>(Op0)) {
687
- Instruction *TrOp = dyn_cast<Instruction>(TI->getOperand (0 ));
686
+ if (auto *TI = dyn_cast<TruncInst>(Op0)) {
688
687
// If 'shift2' is an ashr, we would have to get the sign bit into a funny
689
688
// place. Don't try to do this transformation in this case. Also, we
690
689
// require that the input operand is a shift-by-constant so that we have
691
690
// confidence that the shifts will get folded together. We could do this
692
691
// xform in more cases, but it is unlikely to be profitable.
693
- if (TrOp && I.isLogicalShift () && TrOp->isShift () &&
694
- isa<ConstantInt>(TrOp->getOperand (1 ))) {
692
+ if (I.isLogicalShift () &&
693
+ match (TI->getOperand (0 ), m_Shift (m_Value (), m_ConstantInt ()))) {
694
+ auto *TrOp = cast<Instruction>(TI->getOperand (0 ));
695
+ Type *SrcTy = TrOp->getType ();
696
+
695
697
// Okay, we'll do this xform. Make the shift of shift.
696
- Constant *ShAmt = ConstantExpr::getZExt (Op1, TrOp-> getType () );
698
+ Constant *ShAmt = ConstantExpr::getZExt (Op1, SrcTy );
697
699
// (shift2 (shift1 & 0x00FF), c2)
698
700
Value *NSh = Builder.CreateBinOp (I.getOpcode (), TrOp, ShAmt, I.getName ());
699
701
700
702
// For logical shifts, the truncation has the effect of making the high
701
703
// part of the register be zeros. Emulate this by inserting an AND to
702
704
// clear the top bits as needed. This 'and' will usually be zapped by
703
705
// other xforms later if dead.
704
- unsigned SrcSize = TrOp-> getType () ->getScalarSizeInBits ();
706
+ unsigned SrcSize = SrcTy ->getScalarSizeInBits ();
705
707
unsigned DstSize = TI->getType ()->getScalarSizeInBits ();
706
708
APInt MaskV (APInt::getLowBitsSet (SrcSize, DstSize));
707
709
0 commit comments