[PATCH] D159060: [InstCombine] Make `getKnownSign` a member function of InstCombiner; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 12:55:53 PDT 2023
goldstein.w.n updated this revision to Diff 556705.
goldstein.w.n added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159060/new/
https://reviews.llvm.org/D159060
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Index: llvm/lib/Transforms/InstCombine/InstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -503,6 +503,13 @@
Instruction::BinaryOps BinaryOp, bool IsSigned,
Value *LHS, Value *RHS, Instruction *CxtI) const;
+ // Return true if known negative, false if known positive, and nullopt if
+ // unknown.
+ std::optional<bool> getKnownSign(Value *Op, Instruction *CxtI) const;
+ // Return true if known negative or zero, false if known non-zero positive,
+ // and nullopt if unknown.
+ std::optional<bool> getKnownSignOrZero(Value *Op, Instruction *CxtI) const;
+
/// Performs a few simplifications for operators which are associative
/// or commutative.
bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1016,10 +1016,9 @@
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);
+std::optional<bool> InstCombinerImpl::getKnownSign(Value *Op,
+ Instruction *CxtI) const {
+ KnownBits Known = llvm::computeKnownBits(Op, DL, /*Depth*/ 0, &AC, CxtI, &DT);
if (Known.isNonNegative())
return false;
if (Known.isNegative())
@@ -1033,11 +1032,9 @@
ICmpInst::ICMP_SLT, Op, Constant::getNullValue(Op->getType()), CxtI, DL);
}
-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))
+std::optional<bool>
+InstCombinerImpl::getKnownSignOrZero(Value *Op, Instruction *CxtI) const {
+ if (std::optional<bool> Sign = getKnownSign(Op, CxtI))
return Sign;
Value *X, *Y;
@@ -1049,12 +1046,11 @@
/// 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);
+ InstCombinerImpl &IC) {
+ std::optional<bool> Known1 = IC.getKnownSign(Op1, CxtI);
if (!Known1)
return false;
- std::optional<bool> Known0 = getKnownSign(Op0, CxtI, DL, AC, DT);
+ std::optional<bool> Known0 = IC.getKnownSign(Op0, CxtI);
if (!Known0)
return false;
return *Known0 == *Known1;
@@ -1547,8 +1543,7 @@
if (match(IIOperand, m_Select(m_Value(), m_Neg(m_Value(X)), m_Deferred(X))))
return replaceOperand(*II, 0, X);
- if (std::optional<bool> Known =
- getKnownSignOrZero(IIOperand, II, DL, &AC, &DT)) {
+ if (std::optional<bool> Known = getKnownSignOrZero(IIOperand, 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)
@@ -1675,7 +1670,7 @@
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, II);
if (KnownSign == std::nullopt) {
UseOr = false;
UseAndN = false;
@@ -2448,7 +2443,7 @@
FastMathFlags InnerFlags = cast<FPMathOperator>(Src)->getFastMathFlags();
if ((FMF.allowReassoc() && InnerFlags.allowReassoc()) ||
- signBitMustBeTheSame(Exp, InnerExp, II, DL, &AC, &DT)) {
+ signBitMustBeTheSame(Exp, InnerExp, II, *this)) {
// TODO: Add nsw/nuw probably safe if integer type exceeds exponent
// width.
Value *NewExp = Builder.CreateAdd(InnerExp, Exp);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159060.556705.patch
Type: text/x-patch
Size: 4443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230913/2c0a1c9a/attachment.bin>
More information about the llvm-commits
mailing list