Skip to content

Commit 3fcb00d

Browse files
committed
[InstCombine] restrict shift-trunc-shift fold to opposite direction shifts
This is NFCI because the pattern with 2 left-shifts should get folded independently by smaller folds. The motivation is to refine this block to avoid infinite loops seen with D110170.
1 parent 66c069d commit 3fcb00d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,13 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
853853
return BinaryOperator::CreateShl(X, ConstantInt::get(Ty, AmtSum));
854854
}
855855

856-
// Fold shl(trunc(shift1(x,c1)), c2) -> trunc(shift2(shift1(x,c1),c2))
857-
// If 'shift2' is an ashr, we would have to get the sign bit into a funny
858-
// place. Don't try to do this transformation in this case. Also, we
859-
// require that the input operand is a non-poison shift-by-constant so that
856+
// Fold shl(trunc(shr(x,c1)),c2) -> trunc(and(shl(shr(x,c1),c2),c2'))
857+
// Require that the input operand is a non-poison shift-by-constant so that
860858
// we have confidence that the shifts will get folded together.
861859
Instruction *TrOp;
862860
const APInt *TrShiftAmt;
863861
if (match(Op0, m_OneUse(m_Trunc(m_Instruction(TrOp)))) &&
864-
match(TrOp, m_OneUse(m_Shift(m_Value(), m_APInt(TrShiftAmt)))) &&
862+
match(TrOp, m_OneUse(m_Shr(m_Value(), m_APInt(TrShiftAmt)))) &&
865863
TrShiftAmt->ult(TrOp->getType()->getScalarSizeInBits())) {
866864
Type *SrcTy = TrOp->getType();
867865

0 commit comments

Comments
 (0)