-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SCCP] Add context to SimplifyQuery #100831
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
llvm/test/Transforms/SCCP/float-denormal-simplification.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -passes=sccp -S %s | FileCheck %s | ||
|
||
define float @test_ieee() #0 { | ||
; CHECK-LABEL: @test_ieee( | ||
; CHECK-NEXT: ret float 0x36F4000000000000 | ||
; | ||
%1 = fmul float 2.802596928649634e-44, 2.000000e+00 | ||
ret float %1 | ||
} | ||
|
||
define float @test_preserve_sign() #1 { | ||
; CHECK-LABEL: @test_preserve_sign( | ||
; CHECK-NEXT: ret float 0.000000e+00 | ||
; | ||
%1 = fmul float 2.802596928649634e-44, 2.000000e+00 | ||
ret float %1 | ||
} | ||
|
||
attributes #0 = {"denormal-fp-math"="ieee,ieee"} | ||
attributes #1 = {"denormal-fp-math"="preserve-sign,preserve-sign"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would prefer a more meaningful test. We probably shouldn't be making constant folding dependent on the expected FP environment of the context function, and never flush them. This test should at minimum change to use a canonicalize intrinsic
Uh oh!
There was an error while loading. Please reload this page.
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.
My goal was to imitate the tests in: /llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
since they're minimal and reproduce the "bug" in IPSCCP due to the missing context.
Sorry, but I didn't understand the comment on how it could be more meaningful.
But I do understand your general point of view, my goal for now was to at least make things consistent.
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 mean passing the context should enable more optimizations than this. Replacing the fmul with a canonicalize should show the same thing, but be more true to the IR rules around where the flush would be guaranteed
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.
Understood.
I can work on adding tests that show other optimizations enabled by the context.
Replacing fmul with llvm.canonicalize doesn't reproduce the inconsistent behavior because the context was added to simplifyBinOp (canonicalize is handled elsewhere).
But, if you think the tests shouldn't look like this regardless, I'll work on changing them as well 👍
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.
After diving more into the code it felt like the amount of optimizations is scarce for two reasons:
This leaves: floats and vector types as candidates for other optimizations that can appear in the test.
Regarding floats, I didn't find other optimizations that use the context passed to the function for other than deciding to flush the inputs/output. The context was used to find the denormal-fp-math attribute.
Regarding vector types, I don't have much experience in that area, but I couldn't write a test with a missed optimization opportunity in case the context is missing.
Therefore, with my currently limited knowledge of the code in general, I couldn't come up with better tests.