[llvm] [SimplifyLibCalls] Merge sqrt into the power of exp (PR #79146)

Anton Sidorenko via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 06:23:27 PST 2024


================
@@ -2538,6 +2538,70 @@ Value *LibCallSimplifier::optimizeLog(CallInst *Log, IRBuilderBase &B) {
   return Ret;
 }
 
+// sqrt(exp(X)) -> exp(X * 0.5)
+Value *LibCallSimplifier::mergeSqrtToExp(CallInst *CI, IRBuilderBase &B) {
+  if (!CI->isFast())
----------------
asi-sc wrote:

I'm not sure whether just reassoc is enough. Don't we need afn (approximate calculations for functions) as well (or only afn)?

>From langref for sqrt: `When specified with the fast-math-flag ‘afn’, the result may be approximated using a less accurate calculation`. https://llvm.org/docs/LangRef.html#llvm-sqrt-intrinsic
Or another example from clang users manual for `-fapprox-func`: `For example, a pow(x, 0.25) may be replaced with sqrt(sqrt(x))`. https://clang.llvm.org/docs/UsersManual.html#cmdoption-f-no-approx-func

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


More information about the llvm-commits mailing list