[llvm] [InstCombine] Handle more even/odd math functions (PR #81324)
Artem Tyurin via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 16:11:13 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)
// cos(copysign(x, y)) --> cos(x)
Value *Sign;
Value *Src = Call->getArgOperand(0);
- if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X))) ||
+ if (match(Src, m_FAbs(m_Value(X))) ||
----------------
agentcooper wrote:
Done ✅
I've decided to mimic the existing functionality, so do it only for the even case (where it has a clear win).
https://github.com/llvm/llvm-project/pull/81324
More information about the llvm-commits
mailing list