-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Transforms] Add more cos combinations to SimplifyLibCalls and InstCombine #79699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms Author: AtariDreams (AtariDreams) ChangesWe have this for InstCombine, but forgot to add it for SimplifyLibCalls Full diff: https://github.com/llvm/llvm-project/pull/79699.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 52eef9ab58a4d92..29f7e596f465f7d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1935,7 +1935,8 @@ static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
case LibFunc_cosf:
case LibFunc_cosl:
// cos(-X) --> cos(X)
- if (match(Call->getArgOperand(0), m_FNeg(m_Value(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;
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
048e314
to
35af1a9
Compare
ca7f209
to
dd09878
Compare
e26691e
to
6fa4477
Compare
…mbineCalls Add cos(fabs(x)) -> cos(x) and cos(copysign(x, y)) -> cos(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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be broken out into an optimizeEvenFunction
helper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that in another PR. I think this is good for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In InstCombineAndOrXor we have stripSignOnlyFPOps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but could try to common with stripSignOnlyFPOps in a follow up
%r = call nnan reassoc float @cosf(float %copysign) | ||
ret float %r | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test a vector intrinsic case?
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In InstCombineAndOrXor we have stripSignOnlyFPOps
…mbine (llvm#79699) Add cos(fabs(x)) -> cos(x) and cos(copysign(x, y)) -> cos(x).
* llvm/main: (328 commits) [Flang][OpenMP] Attempt to make map-types-and-sizes.f90 test more agnostic to other architectures [Transforms] Add more cos combinations to SimplifyLibCalls and InstCombine (llvm#79699) [workflows] Close issues used for backports once the PR has been created (llvm#80394) [RISCV] Add support for RISC-V Pointer Masking (llvm#79929) [lldb] Cleanup regex in libcxx formatters (NFC) (llvm#80618) [lldb] Remove unused private TypeCategoryMap methods (NFC) (llvm#80602) [mlir][sparse] refine sparse assembler strategy (llvm#80521) [NFC] Fix typo (llvm#80703) Fix broken ARM processor features test (llvm#80717) [ValueTracking][NFC] Pass `SimplifyQuery` to `computeKnownFPClass` family (llvm#80657) [x86_64][windows][swift] do not use Swift async extended frame for wi… (llvm#80468) [X86] addConstantComments - add FP16 MOVSH asm comments support [X86] Regenerate some vector constant comments missed in recent patches to improve mask predicate handling in addConstantComments [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (llvm#68515) Add some clarification to email check message [GitHub][Workflows] Prevent multiple private email comments (temporarily) (llvm#80648) [workflows] Use /mnt as the build directory on Linux (llvm#80583) [Flang][OpenMP] Initial mapping of Fortran pointers and allocatables for target devices (llvm#71766) [AMDGPU] GlobalISel for f8 conversions (llvm#80503) [AMDGPU] Fixed byte_sel of v_cvt_f32_bf8/v_cvt_f32_fp8 (llvm#80502) ...
Add cos(fabs(x)) -> cos(x) and cos(copysign(x, y)) -> cos(x).