[llvm] [GlobalISel] fdiv to fmul transform (PR #144305)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 03:03:00 PDT 2025


================
@@ -6389,6 +6389,76 @@ bool CombinerHelper::matchCombineFMinMaxNaN(MachineInstr &MI,
   return MatchNaN(1) || MatchNaN(2);
 }
 
+// Combine multiple FDIVs with the same divisor into multiple FMULs by the
+// reciprocal.
+// E.g., (a / D; b / D;) -> (recip = 1.0 / D; a * recip; b * recip)
+bool CombinerHelper::matchRepeatedFPDivisor(
+    MachineInstr &MI, SmallVector<MachineInstr *> &MatchInfo) const {
+  assert(MI.getOpcode() == TargetOpcode::G_FDIV);
+  auto *MF = MI.getMF();
+  const TargetOptions &Options = MF->getTarget().Options;
+
+  Register X = MI.getOperand(1).getReg();
+  Register Y = MI.getOperand(2).getReg();
----------------
jayfoad wrote:

Nit: can you change the comment above to use the same operand name for the divisor that you're using in the code here?

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


More information about the llvm-commits mailing list