aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2023-03-27 09:51:46 -0700
committerCraig Topper <craig.topper@sifive.com>2023-03-27 09:58:50 -0700
commit697a28b380753c754a534ab92b376357a3839e3f (patch)
tree88201dde22eb1835cdf50d38ed27508977fc2c7b /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent9b957b12cc12dd4fbe4014dae9ed2564da1b6d74 (diff)
downloadllvm-697a28b380753c754a534ab92b376357a3839e3f.zip
llvm-697a28b380753c754a534ab92b376357a3839e3f.tar.gz
llvm-697a28b380753c754a534ab92b376357a3839e3f.tar.bz2
[CodeGenPrepare][RISCV] Correct the MathUsed flag for shouldFormOverflowOp
For add, if we match the constant edge case the add isn't used by the compare so we shouldn't check for 2 users. For sub, the compare is not a user of the sub so the math is used if the sub has any users. This regresses RISC-V which I will work on other patches for. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D146786
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index b571b5a..16196b0 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1579,6 +1579,7 @@ static bool matchUAddWithOverflowConstantEdgeCases(CmpInst *Cmp,
/// intrinsic. Return true if any changes were made.
bool CodeGenPrepare::combineToUAddWithOverflow(CmpInst *Cmp,
ModifyDT &ModifiedDT) {
+ bool EdgeCase = false;
Value *A, *B;
BinaryOperator *Add;
if (!match(Cmp, m_UAddWithOverflow(m_Value(A), m_Value(B), m_BinOp(Add)))) {
@@ -1587,11 +1588,12 @@ bool CodeGenPrepare::combineToUAddWithOverflow(CmpInst *Cmp,
// Set A and B in case we match matchUAddWithOverflowConstantEdgeCases.
A = Add->getOperand(0);
B = Add->getOperand(1);
+ EdgeCase = true;
}
if (!TLI->shouldFormOverflowOp(ISD::UADDO,
TLI->getValueType(*DL, Add->getType()),
- Add->hasNUsesOrMore(2)))
+ Add->hasNUsesOrMore(EdgeCase ? 1 : 2)))
return false;
// We don't want to move around uses of condition values this late, so we
@@ -1660,7 +1662,7 @@ bool CodeGenPrepare::combineToUSubWithOverflow(CmpInst *Cmp,
if (!TLI->shouldFormOverflowOp(ISD::USUBO,
TLI->getValueType(*DL, Sub->getType()),
- Sub->hasNUsesOrMore(2)))
+ Sub->hasNUsesOrMore(1)))
return false;
if (!replaceMathCmpWithIntrinsic(Sub, Sub->getOperand(0), Sub->getOperand(1),