[llvm] [X86] Use shift+add/sub for vXi8 splat multiplies (PR #174110)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 1 23:41:20 PST 2026


================
@@ -4836,6 +4836,30 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
   //           x * -0xf800 --> -((x << 16) - (x << 11)) ; (x << 11) - (x << 16)
   if (!UseVP && N1IsConst &&
       TLI.decomposeMulByConstant(*DAG.getContext(), VT, N1)) {
+    // First check if target has custom decomposition info
+    TargetLowering::MulByConstInfo Info =
+        TLI.getMulByConstInfo(VT, ConstValue1);
+    if (Info.IsDecomposable) {
+      // Emit custom decomposition based on target's info
+      SDValue Result;
+      if (Info.NumShifts == 1) {
+        // Single shift: result = N0 << Shift1
+        Result = DAG.getNode(ISD::SHL, DL, VT, N0,
+                             DAG.getConstant(Info.Shift1, DL, VT));
+      } else if (Info.NumShifts == 2) {
+        // Two shifts with add or sub
+        SDValue Shl1 = DAG.getNode(ISD::SHL, DL, VT, N0,
+                                   DAG.getConstant(Info.Shift1, DL, VT));
----------------
arsenm wrote:

This needs to use the correct shift amount type (getShiftAmountTy), not the type of the value 

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


More information about the llvm-commits mailing list