[llvm] 3387e55 - [InstCombine] Use SimplifyQuery in isKnownSign()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 06:22:58 PDT 2024
Author: Nikita Popov
Date: 2024-06-05T15:22:50+02:00
New Revision: 3387e558449e1748a7d4b10f2d9049647c9acc56
URL: https://github.com/llvm/llvm-project/commit/3387e558449e1748a7d4b10f2d9049647c9acc56
DIFF: https://github.com/llvm/llvm-project/commit/3387e558449e1748a7d4b10f2d9049647c9acc56.diff
LOG: [InstCombine] Use SimplifyQuery in isKnownSign()
This enabled the use of DomConditionCache. As such, remove the
explicit isImpliedByDomCondition() call. This is probably not
entirely NFC because these APIs don't support exactly the same
cases.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index b6f339da31f7f..0632f3cfc6dd2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1041,10 +1041,8 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
return nullptr;
}
-static std::optional<bool> getKnownSign(Value *Op, Instruction *CxtI,
- const DataLayout &DL, AssumptionCache *AC,
- DominatorTree *DT) {
- KnownBits Known = computeKnownBits(Op, DL, 0, AC, CxtI, DT);
+static std::optional<bool> getKnownSign(Value *Op, const SimplifyQuery &SQ) {
+ KnownBits Known = computeKnownBits(Op, /*Depth=*/0, SQ);
if (Known.isNonNegative())
return false;
if (Known.isNegative())
@@ -1052,34 +1050,30 @@ static std::optional<bool> getKnownSign(Value *Op, Instruction *CxtI,
Value *X, *Y;
if (match(Op, m_NSWSub(m_Value(X), m_Value(Y))))
- return isImpliedByDomCondition(ICmpInst::ICMP_SLT, X, Y, CxtI, DL);
+ return isImpliedByDomCondition(ICmpInst::ICMP_SLT, X, Y, SQ.CxtI, SQ.DL);
- return isImpliedByDomCondition(
- ICmpInst::ICMP_SLT, Op, Constant::getNullValue(Op->getType()), CxtI, DL);
+ return std::nullopt;
}
-static std::optional<bool> getKnownSignOrZero(Value *Op, Instruction *CxtI,
- const DataLayout &DL,
- AssumptionCache *AC,
- DominatorTree *DT) {
- if (std::optional<bool> Sign = getKnownSign(Op, CxtI, DL, AC, DT))
+static std::optional<bool> getKnownSignOrZero(Value *Op,
+ const SimplifyQuery &SQ) {
+ if (std::optional<bool> Sign = getKnownSign(Op, SQ))
return Sign;
Value *X, *Y;
if (match(Op, m_NSWSub(m_Value(X), m_Value(Y))))
- return isImpliedByDomCondition(ICmpInst::ICMP_SLE, X, Y, CxtI, DL);
+ return isImpliedByDomCondition(ICmpInst::ICMP_SLE, X, Y, SQ.CxtI, SQ.DL);
return std::nullopt;
}
/// Return true if two values \p Op0 and \p Op1 are known to have the same sign.
-static bool signBitMustBeTheSame(Value *Op0, Value *Op1, Instruction *CxtI,
- const DataLayout &DL, AssumptionCache *AC,
- DominatorTree *DT) {
- std::optional<bool> Known1 = getKnownSign(Op1, CxtI, DL, AC, DT);
+static bool signBitMustBeTheSame(Value *Op0, Value *Op1,
+ const SimplifyQuery &SQ) {
+ std::optional<bool> Known1 = getKnownSign(Op1, SQ);
if (!Known1)
return false;
- std::optional<bool> Known0 = getKnownSign(Op0, CxtI, DL, AC, DT);
+ std::optional<bool> Known0 = getKnownSign(Op0, SQ);
if (!Known0)
return false;
return *Known0 == *Known1;
@@ -1628,7 +1622,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
if (std::optional<bool> Known =
- getKnownSignOrZero(IIOperand, II, DL, &AC, &DT)) {
+ getKnownSignOrZero(IIOperand, SQ.getWithInstruction(II))) {
// abs(x) -> x if x >= 0 (include abs(x-y) --> x - y where x >= y)
// abs(x) -> x if x > 0 (include abs(x-y) --> x - y where x > y)
if (!*Known)
@@ -1753,7 +1747,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
bool UseAndN = IID == Intrinsic::smin || IID == Intrinsic::umin;
if (IID == Intrinsic::smax || IID == Intrinsic::smin) {
- auto KnownSign = getKnownSign(X, II, DL, &AC, &DT);
+ auto KnownSign = getKnownSign(X, SQ.getWithInstruction(II));
if (KnownSign == std::nullopt) {
UseOr = false;
UseAndN = false;
@@ -2614,7 +2608,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
FastMathFlags InnerFlags = cast<FPMathOperator>(Src)->getFastMathFlags();
if ((FMF.allowReassoc() && InnerFlags.allowReassoc()) ||
- signBitMustBeTheSame(Exp, InnerExp, II, DL, &AC, &DT)) {
+ signBitMustBeTheSame(Exp, InnerExp, SQ.getWithInstruction(II))) {
// TODO: Add nsw/nuw probably safe if integer type exceeds exponent
// width.
Value *NewExp = Builder.CreateAdd(InnerExp, Exp);
More information about the llvm-commits
mailing list