[llvm] [InstCombine] Handle more even/odd math functions (PR #81324)
Joshua Cranmer via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 11:56:34 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))) ||
----------------
jcranmer-intel wrote:
You can wrap the `fabs` and `copysign` stuff into the symmetric call. e.g., note that `f(fabs(x))` is `f(x)` if `f` is even and `fabs(f(x))` if `f` is odd. That would eliminate this method entirely.
https://github.com/llvm/llvm-project/pull/81324
More information about the llvm-commits
mailing list