[llvm] [GlobalISel] Add multi-way splitting support for wide scalar shifts. (PR #155353)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 01:50:46 PDT 2025


================
@@ -364,6 +364,47 @@ class LegalizerHelper {
                                                       LLT HalfTy,
                                                       LLT ShiftAmtTy);
 
+  /// Multi-way shift legalization: directly split wide shifts into target-sized
+  /// parts in a single step, avoiding recursive binary splitting.
+  LLVM_ABI LegalizeResult narrowScalarShiftMultiway(MachineInstr &MI,
+                                                    LLT TargetTy);
+
+  /// Optimized path for constant shift amounts using static indexing.
+  /// Directly calculates which source parts contribute to each output part
+  /// without generating runtime select chains.
+  LLVM_ABI LegalizeResult narrowScalarShiftByConstantMultiway(MachineInstr &MI,
+                                                              const APInt &Amt,
+                                                              LLT TargetTy,
+                                                              LLT ShiftAmtTy);
+
+  struct ShiftParams {
+    Register WordShift;   // Number of complete words to shift
+    Register BitShift;    // Number of bits to shift within words
+    Register InvBitShift; // Complement bit shift (TargetBits - BitShift)
+    Register Zero;        // Zero constant for SHL/LSHR fill
+    Register SignBit;     // Sign extension value for ASHR fill
+  };
+
+  /// Builds shift parameters from shift amount and operation context.
+  ShiftParams buildConstantShiftParams(unsigned Opcode, const APInt *ConstAmt,
----------------
aemerson wrote:

Yep.

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


More information about the llvm-commits mailing list