[llvm] [X86] Resolve FIXME: Accept live flag if no overflow occurs (PR #86836)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 11:14:03 PDT 2024
================
@@ -54522,14 +54522,27 @@ static SDValue combineADC(SDNode *N, SelectionDAG &DAG,
}
// Fold ADC(C1,C2,Carry) -> ADC(0,C1+C2,Carry)
- // iff the flag result is dead.
- // TODO: Allow flag result if C1+C2 doesn't signed/unsigned overflow.
- if (LHSC && RHSC && !LHSC->isZero() && !N->hasAnyUseOfValue(1)) {
- SDLoc DL(N);
- APInt Sum = LHSC->getAPIntValue() + RHSC->getAPIntValue();
- return DAG.getNode(X86ISD::ADC, DL, N->getVTList(),
- DAG.getConstant(0, DL, LHS.getValueType()),
- DAG.getConstant(Sum, DL, LHS.getValueType()), CarryIn);
+ // if the flag result is dead, or if C1+C2 doesn't signed/unsigned overflow.
+ if (LHSC && RHSC && !LHSC->isZero()) {
+ // Calculate the sum and check for overflow.
+ bool Overflow;
+
+ // Check for signed overflow first. Because it is more involved, let sadd_ov
+ // do the work
+ APInt Sum = LHSC->getAPIntValue().sadd_ov(RHSC->getAPIntValue(), Overflow);
----------------
RKSimon wrote:
Looks like we'd benefit from a `APInt::add_ov(const APInt &RHS, bool &SignedOverflow, bool &UnsignedOverflow)` wtapper helper
https://github.com/llvm/llvm-project/pull/86836
More information about the llvm-commits
mailing list