[llvm] [DAG] foldABSToABD - fallback to value tracking if the (ABS (SUB LHS, RHS)) operands aren't extended (PR #147053)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 5 10:29:40 PDT 2025
================
@@ -11402,16 +11402,25 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N, const SDLoc &DL) {
SDValue AbsOp0 = N->getOperand(0);
unsigned Opc0 = Op0.getOpcode();
- // Check if the operands of the sub are (zero|sign)-extended.
- // TODO: Should we use ValueTracking instead?
+ // Check if the operands of the sub are (zero|sign)-extended, otherwise
+ // fallback to ValueTracking.
if (Opc0 != Op1.getOpcode() ||
(Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND &&
Opc0 != ISD::SIGN_EXTEND_INREG)) {
// fold (abs (sub nsw x, y)) -> abds(x, y)
- // Don't fold this for unsupported types as we lose the NSW handling.
- if (AbsOp0->getFlags().hasNoSignedWrap() && hasOperation(ISD::ABDS, VT) &&
- TLI.preferABDSToABSWithNSW(VT)) {
- SDValue ABD = DAG.getNode(ISD::ABDS, DL, VT, Op0, Op1);
+ if (hasOperation(ISD::ABDS, VT)) {
+ // Don't fold this for unsupported types as we lose the NSW handling.
+ if (TLI.preferABDSToABSWithNSW(VT) &&
----------------
davemgreen wrote:
Could still be a single `if`, if you don't plan to expand them later.
https://github.com/llvm/llvm-project/pull/147053
More information about the llvm-commits
mailing list