diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2024-07-27 15:08:11 +0200 |
|---|---|---|
| committer | Pietro Albini <pietro@pietroalbini.org> | 2024-08-04 12:31:40 +0200 |
| commit | eca0a7e72346ba123ace318a0f9c28c57d990aeb (patch) | |
| tree | e78ad289136e80164eed8b3fe96cea9d12424faf /compiler/rustc_mir_transform/src/jump_threading.rs | |
| parent | 051478957371ee0084a7c0913941d2a8c4757bb9 (diff) | |
| download | rust-eca0a7e72346ba123ace318a0f9c28c57d990aeb.tar.gz rust-eca0a7e72346ba123ace318a0f9c28c57d990aeb.zip | |
Disable jump threading of float equality
Jump threading stores values as `u128` (`ScalarInt`) and does its comparisons for equality as integer comparisons. This works great for integers. Sadly, not everything is an integer. Floats famously have wonky equality semantcs, with `NaN!=NaN` and `0.0 == -0.0`. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong. While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now.
Diffstat (limited to 'compiler/rustc_mir_transform/src/jump_threading.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/jump_threading.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 23cc0c46e73..279fd614918 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -494,6 +494,13 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { BinOp::Ne => ScalarInt::FALSE, _ => return None, }; + if value.const_.ty().is_floating_point() { + // Floating point equality does not follow bit-patterns. + // -0.0 and NaN both have special rules for equality, + // and therefore we cannot use integer comparisons for them. + // Avoid handling them, though this could be extended in the future. + return None; + } let value = value.const_.normalize(self.tcx, self.param_env).try_to_scalar_int()?; let conds = conditions.map(self.arena, |c| Condition { value, |
