Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
rvalue: &Rvalue<'tcx>,
place: Place<'tcx>,
) -> Option<()> {
if place.ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx).ty.is_floating_point() {
// Our apfloat is old and buggy (https://github.com/rust-lang/rust/issues/113409).
// Let's not risk wrong optimization results -- just do nothing for floats.
// This affects at least binary ops and casts, so just skip all rvalues.
// LLVM has a less buggy apfloat and will take care of const-propagation.
return None;
}

match rvalue {
Rvalue::BinaryOp(op, box (left, right))
| Rvalue::CheckedBinaryOp(op, box (left, right)) => {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
rvalue: &Rvalue<'tcx>,
state: &mut State<Self::Value>,
) -> ValueOrPlace<Self::Value> {
if rvalue.ty(self.local_decls, self.tcx).is_floating_point() {
// Our apfloat is old and buggy (https://github.com/rust-lang/rust/issues/113409).
// Let's not risk wrong optimization results -- just do nothing for floats.
// This affects at least binary ops and casts, so just skip all rvalues.
// LLVM has a less buggy apfloat and will take care of const-propagation.
return ValueOrPlace::TOP;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is better to short-circuit in handle_rvalue then. But it would really help if the docs said whether TOP or BOTTOM represents "could be any value, statically unknown"...


match rvalue {
Rvalue::Cast(
kind @ (CastKind::IntToInt
Expand Down