[llvm] [SelectionDAG] Fold constant min/max vector reductions (PR #209190)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 02:53:12 PDT 2026


================
@@ -15077,16 +15101,21 @@ SDValue SelectionDAG::getIdentityElement(unsigned Opcode, const SDLoc &DL,
   case ISD::OR:
   case ISD::XOR:
   case ISD::UMAX:
-    return getConstant(0, DL, VT);
   case ISD::MUL:
-    return getConstant(1, DL, VT);
   case ISD::AND:
-  case ISD::UMIN:
-    return getAllOnesConstant(DL, VT);
+  case ISD::UMIN: {
+    std::optional<APInt> Identity =
+        getIntegerIdentity(Opcode, VT.getScalarSizeInBits());
+    assert(Identity && "Unexpected integer identity opcode");
+    return getConstant(*Identity, DL, VT);
+  }
   case ISD::SMAX:
-    return getConstant(APInt::getSignedMinValue(VT.getSizeInBits()), DL, VT);
-  case ISD::SMIN:
-    return getConstant(APInt::getSignedMaxValue(VT.getSizeInBits()), DL, VT);
+  case ISD::SMIN: {
+    std::optional<APInt> Identity =
+        getIntegerIdentity(Opcode, VT.getSizeInBits());
----------------
RKSimon wrote:

getScalarSizeInBits - I'm amazed this didn't break in the original

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


More information about the llvm-commits mailing list