[llvm] [AArch64] Combine manual reciprocal square root refinement into FRSQRTS. (PR #172067)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 03:45:46 PST 2026


================
@@ -28356,6 +28339,71 @@ static SDValue performCTPOPCombine(SDNode *N,
   return DAG.getNegative(NegPopCount, DL, VT);
 }
 
+// Combine manual Newton-Raphson reciprocal square root refinement patterns
+// into FRSQRTS instructions.
+//
+// The Newton-Raphson iteration for rsqrt is:
+//   r' = r * (1.5 - 0.5 * x * r * r)
+//
+// This appears as:
+//   fma(r, 1.5, mul(mul(mul(x, -0.5), r), r * r))
+//   where r = frsqrte(x) is the initial estimate.
+//
+// We convert this to use FRSQRTS: r * frsqrts(x * r, r).
+static SDValue
+performRSQRTRefinementCombine(SDNode *N, SelectionDAG &DAG,
+                              const AArch64Subtarget *Subtarget) {
+  using namespace SDPatternMatch;
+
----------------
arsenm wrote:

I'd also verify it's bit identical with FTZ-DAZ enabled

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


More information about the llvm-commits mailing list