[llvm] [DAGCombiner] Use canonical shift amount type when decomposing a multiply. (PR #222211)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 01:50:08 PDT 2026


================
@@ -5027,12 +5027,13 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
       ShAmt += TZeros;
       assert(ShAmt < BitWidth &&
              "multiply-by-constant generated out of bounds shift");
-      SDValue Shl =
-          DAG.getNode(ISD::SHL, DL, VT, N0, DAG.getConstant(ShAmt, DL, VT));
+      SDValue Shl = DAG.getNode(ISD::SHL, DL, VT, N0,
+                                DAG.getShiftAmountConstant(ShAmt, VT, DL));
       SDValue R =
-          TZeros ? DAG.getNode(MathOp, DL, VT, Shl,
-                               DAG.getNode(ISD::SHL, DL, VT, N0,
-                                           DAG.getConstant(TZeros, DL, VT)))
+          TZeros ? DAG.getNode(
+                       MathOp, DL, VT, Shl,
+                       DAG.getNode(ISD::SHL, DL, VT, N0,
+                                   DAG.getShiftAmountConstant(TZeros, VT, DL)))
                  : DAG.getNode(MathOp, DL, VT, Shl, N0);
----------------
RKSimon wrote:

You might be able to simplify this formatting a little by reducing the nesting:
```
SDValue R =
          TZeros ? DAG.getNode(ISD::SHL, DL, VT, N0, DAG.getShiftAmountConstant(TZeros, VT, DL))
                      : N0;
R = DAG.getNode(MathOp, DL, VT, Shl, R);
```

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


More information about the llvm-commits mailing list