[llvm] [ValueTracking] Improve `isImpliedCondICmps` to handle binops (PR #69840)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 21 11:01:00 PDT 2023
================
@@ -8298,6 +8306,32 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
return LPred == RPred;
}
+ // handle R0 = L0 binop V
+ Value *R0Op1 = nullptr;
+ if (match(L1, m_APInt(LC)) && match(R1, m_APInt(RC)) &&
+ match(R0, m_c_BinOp(m_Specific(L0), m_Value(R0Op1)))) {
+ ConstantRange LHSRange = ConstantRange::makeExactICmpRegion(LPred, *LC);
+ ConstantRange CR = ConstantRange::makeExactICmpRegion(RPred, *RC);
+ // TODO: use contextual information from SimplifyQuery
+ ConstantRange RHSRange = computeConstantRange(
+ R0Op1, ICmpInst::isSigned(RPred), /*UseInstrInfo*/ true, /*AC*/ nullptr,
+ /*CtxI*/ nullptr, /*DT*/ nullptr, Depth);
+ auto BO = cast<BinaryOperator>(R0);
+ if (BO->getOperand(0) != L0)
+ std::swap(LHSRange, RHSRange);
+ unsigned NoWrapKind = 0;
+ if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(BO)) {
+ if (OBO->hasNoUnsignedWrap())
+ NoWrapKind |= OverflowingBinaryOperator::NoUnsignedWrap;
+ if (OBO->hasNoSignedWrap())
+ NoWrapKind |= OverflowingBinaryOperator::NoSignedWrap;
+ }
+ ConstantRange Range =
+ LHSRange.overflowingBinaryOp(BO->getOpcode(), RHSRange, NoWrapKind);
----------------
goldsteinn wrote:
Should `LHSRange` here be for `L0`?
https://github.com/llvm/llvm-project/pull/69840
More information about the llvm-commits
mailing list