-
Notifications
You must be signed in to change notification settings - Fork 248
Fix constant folding of booleans casted to integers #2805
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
Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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.
Change looks good, might be useful to know the context of when this is important / what the downstream breakage we saw was.
I'm a bit confused by the statement:
(unsigned)(true) is currently converted to a -1 constant in MLIR
What does -1 in unsigned
mean? U..._MAX
?
Signed-off-by: Anna Gringauze <[email protected]>
…x-const-folding Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
I included an example in the description and the reference to the bug it fixes
Constant folding folds the cast, so in this particular example we end up with an integer constant with value of -1, of type i32 (see example in the description). It would behave the same as uint32 max, yes, which is incorrect in this case, we should const fold it to |
Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Signed-off-by: Anna Gringauze <[email protected]>
…x-const-folding Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
…x-const-folding Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Signed-off-by: Anna Gringauze <[email protected]>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
patch. Don't try to preserve NOPs, etc. but fix sign bit truncation issue for all integral types in the IR. Signed-off-by: Eric Schweitz <[email protected]>
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.
Thanks for all the tests!
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Description
Fix constant folding of casts of integers.
Using the MLIR below
The constant folding creates the following code without changing
<c>
:This leads to incorrect values in constants when constant folding is invoked, for example,
(unsigned)(true)
is currently converted to a-1
integer constant.See added tests in
targettests/execution/cast.cpp
for more examples.This PR updates constant folding to cast the source of the cast instruction to its original type before folding into a constant of a new type.
Example:
Quake before the fix:
Quake after the fix:
Result before the fix:
{ 0:0000 }
Result after the fix:
{ 1:0000 }
Closes: #2804