-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Disable jump threading of float equality #128271
Merged
bors
merged 1 commit into
rust-lang:master
from
Noratrieb:jump-into-a-can-of-worms-called-float-equality
Jul 27, 2024
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 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
59 changes: 59 additions & 0 deletions
59
tests/mir-opt/jump_threading.floats.JumpThreading.panic-abort.diff
This file contains 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,59 @@ | ||
- // MIR for `floats` before JumpThreading | ||
+ // MIR for `floats` after JumpThreading | ||
|
||
fn floats() -> u32 { | ||
let mut _0: u32; | ||
let _1: f64; | ||
let mut _2: bool; | ||
let mut _3: bool; | ||
let mut _4: f64; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = const true; | ||
- switchInt(move _2) -> [0: bb2, otherwise: bb1]; | ||
+ goto -> bb1; | ||
} | ||
|
||
bb1: { | ||
_1 = const -0f64; | ||
goto -> bb3; | ||
} | ||
|
||
bb2: { | ||
_1 = const 1f64; | ||
goto -> bb3; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
_4 = _1; | ||
_3 = Eq(move _4, const 0f64); | ||
switchInt(move _3) -> [0: bb5, otherwise: bb4]; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_4); | ||
_0 = const 0_u32; | ||
goto -> bb6; | ||
} | ||
|
||
bb5: { | ||
StorageDead(_4); | ||
_0 = const 1_u32; | ||
goto -> bb6; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_3); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
tests/mir-opt/jump_threading.floats.JumpThreading.panic-unwind.diff
This file contains 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,59 @@ | ||
- // MIR for `floats` before JumpThreading | ||
+ // MIR for `floats` after JumpThreading | ||
|
||
fn floats() -> u32 { | ||
let mut _0: u32; | ||
let _1: f64; | ||
let mut _2: bool; | ||
let mut _3: bool; | ||
let mut _4: f64; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = const true; | ||
- switchInt(move _2) -> [0: bb2, otherwise: bb1]; | ||
+ goto -> bb1; | ||
} | ||
|
||
bb1: { | ||
_1 = const -0f64; | ||
goto -> bb3; | ||
} | ||
|
||
bb2: { | ||
_1 = const 1f64; | ||
goto -> bb3; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
_4 = _1; | ||
_3 = Eq(move _4, const 0f64); | ||
switchInt(move _3) -> [0: bb5, otherwise: bb4]; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_4); | ||
_0 = const 0_u32; | ||
goto -> bb6; | ||
} | ||
|
||
bb5: { | ||
StorageDead(_4); | ||
_0 = const 1_u32; | ||
goto -> bb6; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_3); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
This file contains 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
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.
While this PR is an easily backportable targeted fix, it might be worth thinking about how to prevent this more generally. It seems highly confusing that a method called
try_to_scalar_int
will return floats, and it doesn't surprise me that this pass was confused by this. I would also expecttry_to_scalar_int
to be OK for comparing bitwise.Maybe it should be changed to not return anything for floats?
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.
Possibly bad suggestion, but maybe we shouldn't use valtrees to represent floats 🤔
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.
try_to_bitwise_repr
?