aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index b7958978c450..54490c46dfae 100644
--- a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -366,14 +366,14 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
Type *Ty = I.getType();
- // Find a matching one-use shift by constant. The fold is not valid if the sum
+ // Find a matching shift by constant. The fold is not valid if the sum
// of the shift values equals or exceeds bitwidth.
- // TODO: Remove the one-use check if the other logic operand (Y) is constant.
Value *X, *Y;
- auto matchFirstShift = [&](Value *V) {
- APInt Threshold(Ty->getScalarSizeInBits(), Ty->getScalarSizeInBits());
- return match(V,
- m_OneUse(m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
+ auto matchFirstShift = [&](Value *V, Value *W) {
+ unsigned Size = Ty->getScalarSizeInBits();
+ APInt Threshold(Size, Size);
+ return match(V, m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0))) &&
+ (V->hasOneUse() || match(W, m_ImmConstant())) &&
match(ConstantExpr::getAdd(C0, C1),
m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
};
@@ -382,9 +382,9 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
// is not so we cannot reoder if we match operand(1) and need to keep the
// operands in their original positions.
bool FirstShiftIsOp1 = false;
- if (matchFirstShift(BinInst->getOperand(0)))
+ if (matchFirstShift(BinInst->getOperand(0), BinInst->getOperand(1)))
Y = BinInst->getOperand(1);
- else if (matchFirstShift(BinInst->getOperand(1))) {
+ else if (matchFirstShift(BinInst->getOperand(1), BinInst->getOperand(0))) {
Y = BinInst->getOperand(0);
FirstShiftIsOp1 = BinInst->getOpcode() == Instruction::Sub;
} else