[llvm] [InstCombine] Transform high latency, dependent FSQRT/FDIV into FMUL (PR #87474)

Sushant Gokhale via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 00:44:21 PST 2025


================
@@ -666,6 +667,90 @@ Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
   return nullptr;
 }
 
+// Check legality for transforming
+// x = 1.0/sqrt(a)
+// r1 = x * x;
+// r2 = a/sqrt(a);
----------------
sushgokh wrote:

>but it's not clear to me why you're transforming a/sqrt(a) as part of this pattern

we would like to express `x = r1 * r2` where r1 and r2 are in suitable form. If r2 is not in required form, there is no point in doing this transformation(i.e. we wont be saving on 1 division in the backend).
We cant wait for the backend to transform r2 here.

> I think it's definitely a transformation we want to allow, but I would argue that it requires more than just reassoc.

as far as I remember, I had this discussion with @jcranmer-intel on this PR itself. This is just considered algebraic-rewrite and hence, the reassoc flag. But if there any other flags required, coming post acceptance of his proposal, I am not sure if we should wait.

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


More information about the llvm-commits mailing list