-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Missed optimization in math expression: tan(a) * cos(a) == sin(a) #34950
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
Comments
Could be in InstCombine. |
See a lot of optimizations here: https://github.com/gcc-mirror/gcc/blob/07b69d3f1cd3dd8ebb0af1fbff95914daee477d2/gcc/match.pd |
Hi, |
Yes, this is still open. I'm not sure if Dmitry is able to respond, but the last comment in D41283 suggested that we would add an llvm.tan* intrinsic corresponding to sin/cos. I still think that's the right 1st step to move this forward. |
Sorry for the delay. I'm quit busy at the moment doing my primary job, but still working on this. In a couple of weeks I'm returning to this patch. |
mentioned in issue #34959 |
Hi @zamazan4ik , I am new to LLVM. Can I work on this issue? please mention any resources that can help. |
@llvm/issue-subscribers-good-first-issue |
@elhewaty I say go for it - nobody has assigned it and the ticket has been quiet for long enough! |
Same should be done for hyperbolic equivalents. |
It looks like the first task will be to add llvm.tan.* intrinsics - that was the first step identified on D41283 but it didn't go anywhere Same if you're going to add the cosh/sinh/tanh equivalents |
Hi, I'm starting to work with LLVM, and if this issue can be solved without a deep understanding of all the optimizations I could try handling it. I have been checking the code, and maybe optimization can be included in: https://github.com/llvm/llvm-project/blob/2e999b7dd1934a44d38c3a753460f1e5a217e9a5/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp ( For what @RKSimon said, does not exist a |
Sorry, previously I said that it would fit in llvm-project/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Lines 1564 to 1587 in 2e999b7
InstCombineMulDivRem.cpp ), there are already cases written cases of Intrinsic::cos and Intrinsic::sin . In any case I will wait for an answer if is needed to implement a Intrinsic::tan .
|
Issue #61617 noticed this similar fold was missing as well:
|
Hi @RKSimon, I find this issue an excellent chance to learn different parts of LLVM. Do you think it's still the right direction to add
|
@junaire That plan looks good to me - (2) might involve extra work for correctly lowering tan intrinsics on specific targets, and you will have to do some minor work in the clang frontend to correctly match tan function calls. |
I've put up https://reviews.llvm.org/D146905 to add |
The patch is abandoned due to some objections about adding more fp intrinsics from some reviewers. |
Looks like we added a pattern match for |
That's a shame, I'd have gone with the llvm.tan.* approach, but I can understand if people who know the code better worry about diverging intrinsics / LibFunc implementations. I can't think of a way to avoid the TLI dependency but you might be able to add a TargetPatternMatch.h header somewhere inside Analysis that you can wrap PatternMatch.h and add the equivalent TLI pattern match handling to - and then SimplifyLibCalls includes that instead of PatternMatch.h directly? |
I don't know but just some random thought - Is it possible to canonicalize |
Do I understand correctly the proof is not applicable here because of unsupported trigonometry intrinsics in alive2? |
@junaire, are you still working on it or I could proceed with that? |
no i dont, i think you should talk to some maintainers about how we can handle this, probably start an rfc or something. i remember there was some disagreement about the patch and eventually i gave up... |
@junaire RFC was approved about a year ago. https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294 @amordo Really excited to see people use the new trig intrinsics for inst combines. |
Extended Description
clang(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this code:
generates this assembly:
gcc(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags generates this:
The text was updated successfully, but these errors were encountered: