[llvm] GlobalISel needs fdiv 1 / sqrt(x) to rsq combine (PR #78673)

Pierre van Houtryve via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 01:07:10 PST 2024


================
@@ -33,6 +33,11 @@ def rcp_sqrt_to_rsq : GICombineRule<
          [{ return matchRcpSqrtToRsq(*${rcp}, ${matchinfo}); }]),
   (apply [{ Helper.applyBuildFn(*${rcp}, ${matchinfo}); }])>;
 
+def fdiv_by_sqrt_to_rsq : GICombineRule<
+  (defs root:$root),
+  (match (G_FSQRT $sqrt, $x, (MIFlags FmContract)),
+         (G_FDIV $dst, $y, $sqrt, (MIFlags FmContract)):$root),
----------------
Pierre-vh wrote:

Need to check that `G_FSQRT` has one user, so we don't do the combine if it means the `G_FSQRT` stays.
(also means you will need a test with a `G_FSQRT` that has multiple users)

To check `hasOneUse`, you can use a C++ predicate on top of the pattern that calls `MRI.hasOneUse` on `${sqrt}`

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


More information about the llvm-commits mailing list