[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);
+//
+// TO
+//
+// r1 = 1/a
+// r2 = sqrt(a)
+// x = r1 * r2
+// This transform works only when 'a' is known positive.
+static bool isFSqrtDivToFMulLegal(Instruction *X,
+ SmallPtrSetImpl<Instruction *> &R1,
+ SmallPtrSetImpl<Instruction *> &R2) {
+ BasicBlock *BBx = X->getParent();
+ BasicBlock *BBr1 = (*R1.begin())->getParent();
+ BasicBlock *BBr2 = (*R2.begin())->getParent();
+
+ CallInst *FSqrt = cast<CallInst>(X->getOperand(1));
----------------
sushgokh wrote:
Firstly, any attempt to call the func directly where the cast<> fails should be immediately visible in the debug build.
Second, This part is keep different just to increase readability and seperate functionally different things. The scenario you have mentioned is bound to happen everywhere. For the same reason, I have mentioned in the description of the function that how should `x/r1/r2` look like. If you are not satisfied with the cast, maybe I can add an `assert`.
https://github.com/llvm/llvm-project/pull/87474
More information about the llvm-commits
mailing list