[llvm] [DAG] Combine manual reciprocal square root refinement into FRSQRTS. (PR #172067)
Valeriy Savchenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 7 08:55:44 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;
+
----------------
SavchenkoValeriy wrote:
>From my little experimentation, it looks like the target `frsqrts` version produces bit-equivalent results to `(fma(-(x * r), r, 3.0) * 0.5) * r`, but that also can't be used for a formal proof.
https://github.com/llvm/llvm-project/pull/172067
More information about the llvm-commits
mailing list