[llvm] Add cos(fabs(x)) -> cos(x) to SimplifyLibCalls (PR #79699)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 27 09:39:41 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>

We have this for InstCombine, but forgot to add it for SimplifyLibCalls

---
Full diff: https://github.com/llvm/llvm-project/pull/79699.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+2-1) 


``````````diff
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 52eef9ab58a4d92..29f7e596f465f7d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1935,7 +1935,8 @@ static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
   case LibFunc_cosf:
   case LibFunc_cosl:
     // cos(-X) --> cos(X)
-    if (match(Call->getArgOperand(0), m_FNeg(m_Value(X))))
+    // cos(fabs(x)) -> cos(x)
+    if (match(Call->getArgOperand(0), m_FNeg(m_Value(X))) || match(Call->getArgOperand(0), m_FAbs(m_Value(X))))
       return copyFlags(*Call,
                        B.CreateCall(Call->getCalledFunction(), X, "cos"));
     break;

``````````

</details>


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


More information about the llvm-commits mailing list