[llvm] [InstCombine] Handle more even/odd math functions (PR #81324)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 11 23:33:26 PST 2024


================
@@ -1919,27 +1919,14 @@ static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
   // TODO: Can this be shared to also handle LLVM intrinsics?
   Value *X;
   switch (Func) {
-  case LibFunc_sin:
-  case LibFunc_sinf:
-  case LibFunc_sinl:
-  case LibFunc_tan:
-  case LibFunc_tanf:
-  case LibFunc_tanl:
-    // sin(-X) --> -sin(X)
-    // tan(-X) --> -tan(X)
-    if (match(Call->getArgOperand(0), m_OneUse(m_FNeg(m_Value(X)))))
-      return B.CreateFNeg(
-          copyFlags(*Call, B.CreateCall(Call->getCalledFunction(), X)));
-    break;
   case LibFunc_cos:
   case LibFunc_cosf:
   case LibFunc_cosl: {
-    // cos(-x) --> cos(x)
     // cos(fabs(x)) --> cos(x)
----------------
dtcxzyw wrote:

I think `f(fabs(x)) --> f(x)` and `f(copysign(x, y)) --> f(x)` also hold for even functions.

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


More information about the llvm-commits mailing list