[llvm] [LLVM][SelectionDAG] Add poison/undef folds for signed/unsigned max/min. (PR #149334)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 17 23:03:03 PDT 2025


================
@@ -7895,16 +7904,30 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     case ISD::AND:
     case ISD::SSUBSAT:
     case ISD::USUBSAT:
+    case ISD::UMIN:
       // fold op(arg1, undef) -> 0, fold op(arg1, poison) -> poison.
       return N2.getOpcode() == ISD::POISON ? getPOISON(VT)
                                            : getConstant(0, DL, VT);
     case ISD::OR:
     case ISD::SADDSAT:
     case ISD::UADDSAT:
+    case ISD::UMAX:
       // fold op(arg1, undef) -> an all-ones constant, fold op(arg1, poison) ->
       // poison.
       return N2.getOpcode() == ISD::POISON ? getPOISON(VT)
                                            : getAllOnesConstant(DL, VT);
+    case ISD::SMAX:
+      return N2.getOpcode() == ISD::POISON
+                 ? getPOISON(VT)
----------------
arsenm wrote:

Can reuse N2 instead of constructing a new poison 

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


More information about the llvm-commits mailing list