[llvm] [LLVM][SelectionDAG] Align poison/undef binop folds with IR. (PR #149334)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 05:59:43 PDT 2025


================
@@ -7869,21 +7870,29 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       case ISD::SSUBSAT:
       case ISD::USUBSAT:
         // fold op(undef, arg2) -> 0, fold op(poison, arg2) -> poison.
-        return N1.getOpcode() == ISD::POISON ? getPOISON(VT)
-                                             : getConstant(0, DL, VT);
+        return N1.getOpcode() == ISD::POISON ? N1 : getConstant(0, DL, VT);
       }
     }
   }
 
   // Fold a bunch of operators when the RHS is undef.
   if (N2.isUndef()) {
-    switch (Opcode) {
-    case ISD::XOR:
-      if (N1.isUndef())
+    if (N1.isUndef()) {
----------------
paulwalker-arm wrote:

I've take this to mean you're happy for this PR to implement full coverage so I've restructured the code so poison handling is now separate and the previous `isUNDEF()` code now explicitly only operates on `ISD::UNDEF`.

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


More information about the llvm-commits mailing list