[llvm] Retry "[SDAG] (abs (add nsw a, -b)) -> (abds a, b) (#175801)" (PR #186659)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 08:44:02 PDT 2026


================
@@ -11850,34 +11850,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.
----------------
jayfoad wrote:

The comment doesn't seem right. You're only avoiding INT_MIN. Did you mean make sure (abs B) is positive?

https://github.com/llvm/llvm-project/pull/186659


More information about the llvm-commits mailing list