[llvm] [CodeGen] Emit a more efficient magic number multiplication for exact udivs (PR #87161)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 02:06:35 PDT 2024


================
@@ -5071,8 +5071,36 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
   LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
   auto &MIB = Builder;
 
+  bool UseSRL = false;
   bool UseNPQ = false;
   SmallVector<Register, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
+  SmallVector<Register, 16> Shifts, Factors;
+  auto *RHSDefInstr = cast<GenericMachineInstr>(getDefIgnoringCopies(RHS, MRI));
+  bool IsSplat = getIConstantSplatVal(*RHSDefInstr, MRI).has_value();
+
+  auto BuildExactUDIVPattern = [&](const Constant *C) {
+    // Don't recompute inverses for each splat element.
----------------
jayfoad wrote:

Could apply this optimization to the non-exact case too? And to the SelectionDAG code?

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


More information about the llvm-commits mailing list