[llvm] [PartiallyInlineLibCalls] Emit missed- and passed-optimization remarks when partially inlining sqrt (PR #123966)

Tibor Győri via llvm-commits llvm-commits at lists.llvm.org
Sun May 18 09:50:38 PDT 2025


================
@@ -56,6 +56,20 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
   // dst = phi(v0, v1)
   //
 
+  ORE->emit([&]() {
+    return OptimizationRemark(DEBUG_TYPE, "SqrtPartiallyInlined",
+                              Call->getDebugLoc(), &CurrBB)
+           << "Partially inlined call to sqrt function despite having to use "
+              "errno for error handling: target has fast sqrt instruction";
----------------
TiborGY wrote:

But doesn't `optimizeSQRT` only get called if `TTI->haveFastSqrt(Call->getType()) == true`?
This is its only call site:
```
        if (TTI->haveFastSqrt(Call->getType()) &&
            optimizeSQRT(Call, CalledFunc, *CurrBB, BB, TTI,
                         DTU ? &*DTU : nullptr, ORE))
          break;
```
If the target does not have fast sqrt, the `&&` gets short-circuited to false and `optimizeSQRT` is never called.
Therefore `optimizeSQRT` implicitly knows the HW sqrt is fast, in the context of the current codebase.
But you are right, this is quite brittle, so I have moved the remark after the condition that may call `optimizeSQRT`.

FWIW, I have taken the "fast sqrt instruction" language from here:
https://github.com/llvm/llvm-project/blob/9c60431b673c478606e63ff1e47860eb4eb6af09/llvm/include/llvm/Analysis/TargetTransformInfo.h#L1048C1-L1049C37

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


More information about the llvm-commits mailing list