[llvm] [Transforms] Add more cos combinations to SimplifyLibCalls and InstCombine (PR #79699)

Joshua Cranmer via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 12:26:26 PST 2024


================
@@ -2488,11 +2488,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
   }
   case Intrinsic::cos:
   case Intrinsic::amdgcn_cos: {
-    Value *X;
+    Value *X, *Sign;
     Value *Src = II->getArgOperand(0);
-    if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X)))) {
-      // cos(-x) -> cos(x)
-      // cos(fabs(x)) -> cos(x)
+    if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X))) ||
+        match(Src, m_CopySign(m_Value(X), m_Value(Sign)))) {
+      // cos(-x) --> cos(x)
+      // cos(fabs(x)) --> cos(x)
+      // cos(copysign(x, y)) --> cos(x)
----------------
jcranmer-intel wrote:

I think this could be broken out into an `optimizeEvenFunction` helper method.

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


More information about the llvm-commits mailing list