[llvm] [DAG] Use known-bits when creating umulh/smulh. (PR #160916)

David Green via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 31 10:04:25 PDT 2025


================
@@ -10821,18 +10825,17 @@ static SDValue combineShiftToMULH(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
   }
 
   SDValue MulhRightOp;
-  if (ConstantSDNode *Constant = isConstOrConstSplat(RightOp)) {
-    unsigned ActiveBits = IsSignExt
-                              ? Constant->getAPIntValue().getSignificantBits()
-                              : Constant->getAPIntValue().getActiveBits();
-    if (ActiveBits > NarrowVTSize)
+  if (LeftOp.getOpcode() != RightOp.getOpcode()) {
+    if (IsZeroExt && ShiftOperand.hasOneUse() &&
+        DAG.computeKnownBits(RightOp).countMinLeadingZeros() >= NarrowVTSize) {
+      MulhRightOp = DAG.getNode(ISD::TRUNCATE, DL, NarrowVT, RightOp);
+    } else if (IsSignExt && ShiftOperand.hasOneUse() &&
+               DAG.ComputeNumSignBits(RightOp) > NarrowVTSize) {
----------------
davemgreen wrote:

As the mul needs twice the number of bits it was assuming they were the same. There is a check below that `WideVT.getScalarSizeInBits() == 2 * NarrowVTSize`.

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


More information about the llvm-commits mailing list