[llvm] [Transforms] Add cos(fabs(x)) -> cos(x) to SimplifyLibCalls (PR #79699)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 09:48:10 PST 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/79699
>From 3deefd44a6deb34e648b36c0497add9a47900945 Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Sat, 27 Jan 2024 12:38:19 -0500
Subject: [PATCH] [Transforms] Add cos(fabs(x)) -> cos(x) to SimplifyLibCalls
We have this for InstCombine, but forgot to add it for SimplifyLibCalls
---
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 52eef9ab58a4d92..a1038c06daea4bb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1934,8 +1934,10 @@ static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
case LibFunc_cos:
case LibFunc_cosf:
case LibFunc_cosl:
- // cos(-X) --> cos(X)
- if (match(Call->getArgOperand(0), m_FNeg(m_Value(X))))
+ // cos(-x) --> cos(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;
More information about the llvm-commits
mailing list