[llvm] Retry "[SDAG] (abs (add nsw a, -b)) -> (abds a, b) (#175801)" (PR #186659)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 07:30:13 PDT 2026
================
@@ -11854,34 +11854,73 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N, const SDLoc &DL) {
EVT VT = N->getValueType(0);
SDValue Op0, Op1;
- if (!sd_match(N, m_Abs(m_Sub(m_Value(Op0), m_Value(Op1)))))
+ if (!sd_match(N, m_Abs(m_AnyOf(m_Sub(m_Value(Op0), m_Value(Op1)),
+ m_Add(m_Value(Op0), m_Value(Op1))))))
return SDValue();
SDValue AbsOp0 = N->getOperand(0);
+ bool IsAdd = AbsOp0.getOpcode() == ISD::ADD;
+ // Make sure (neg B) is positive.
+ if (IsAdd) {
+ // Elements of Op1 must be constant and != VT.minSignedValue() (or undef)
+ std::function<bool(ConstantSDNode *)> IsNotMinSignedInt =
+ [VT](ConstantSDNode *C) {
----------------
RKSimon wrote:
(style) this is one of the few times we tend to use auto:
```
auto IsNotMinSignedInt = [VT](ConstantSDNode *C) {
```
https://github.com/llvm/llvm-project/pull/186659
More information about the llvm-commits
mailing list