[llvm] [Transforms] Create more optimizing functions to fold inverse trig pairs (PR #77799)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 23:37:33 PST 2024


================
@@ -2635,6 +2635,99 @@ Value *LibCallSimplifier::optimizeTan(CallInst *CI, IRBuilderBase &B) {
   return Ret;
 }
 
+Value *LibCallSimplifier::optimizeSinh(CallInst *CI, IRBuilderBase &B) {
+  Module *M = CI->getModule();
+  Function *Callee = CI->getCalledFunction();
+  Value *Ret = nullptr;
+  StringRef Name = Callee->getName();
+  if (UnsafeFPShrink && Name == "sinh" && hasFloatVersion(M, Name))
+    Ret = optimizeUnaryDoubleFP(CI, B, TLI, true);
+
+  Value *Op1 = CI->getArgOperand(0);
+  auto *OpC = dyn_cast<CallInst>(Op1);
+  if (!OpC)
+    return Ret;
+
+  // Both calls must be 'fast' in order to remove them.
+  if (!CI->isFast() || !OpC->isFast())
+    return Ret;
+
+  // sinh(asinh(x)) -> x
+  // sinhf(asinhf(x)) -> x
+  // sinhl(asinhl(x)) -> x
+  LibFunc Func;
+  Function *F = OpC->getCalledFunction();
+  if (F && TLI->getLibFunc(F->getName(), Func) &&
+      isLibFuncEmittable(M, TLI, Func) &&
+      ((Func == LibFunc_asinh && Callee->getName() == "sinh") ||
+       (Func == LibFunc_asinhf && Callee->getName() == "sinhf") ||
+       (Func == LibFunc_asinhl && Callee->getName() == "sinhl")))
+    Ret = OpC->getArgOperand(0);
+  return Ret;
+}
+
+Value *LibCallSimplifier::optimizeCosh(CallInst *CI, IRBuilderBase &B) {
+  Module *M = CI->getModule();
+  Function *Callee = CI->getCalledFunction();
+  Value *Ret = nullptr;
+  StringRef Name = Callee->getName();
+  if (UnsafeFPShrink && Name == "cosh" && hasFloatVersion(M, Name))
+    Ret = optimizeUnaryDoubleFP(CI, B, TLI, true);
+
+  Value *Op1 = CI->getArgOperand(0);
+  auto *OpC = dyn_cast<CallInst>(Op1);
+  if (!OpC)
+    return Ret;
+
+  // Both calls must be 'fast' in order to remove them.
+  if (!CI->isFast() || !OpC->isFast())
----------------
arsenm wrote:

Ditto 

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


More information about the llvm-commits mailing list