Skip to content

Commit 44c6999

Browse files
committed
disable ConstProp of floats
1 parent 4b6749b commit 44c6999

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+8
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
520520
rvalue: &Rvalue<'tcx>,
521521
place: Place<'tcx>,
522522
) -> Option<()> {
523+
if place.ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx).ty.is_floating_point() {
524+
// Our apfloat is old and buggy (https://github.com/rust-lang/rust/issues/113409).
525+
// Let's not risk wrong optimization results -- just do nothing for floats.
526+
// This affects at least binary ops and casts, so just skip all rvalues.
527+
// LLVM has a less buggy apfloat and will take care of const-propagation.
528+
return None;
529+
}
530+
523531
match rvalue {
524532
Rvalue::BinaryOp(op, box (left, right))
525533
| Rvalue::CheckedBinaryOp(op, box (left, right)) => {

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
193193
rvalue: &Rvalue<'tcx>,
194194
state: &mut State<Self::Value>,
195195
) -> ValueOrPlace<Self::Value> {
196+
if rvalue.ty(self.local_decls, self.tcx).is_floating_point() {
197+
// Our apfloat is old and buggy (https://github.com/rust-lang/rust/issues/113409).
198+
// Let's not risk wrong optimization results -- just do nothing for floats.
199+
// This affects at least binary ops and casts, so just skip all rvalues.
200+
// LLVM has a less buggy apfloat and will take care of const-propagation.
201+
return ValueOrPlace::TOP;
202+
}
203+
196204
match rvalue {
197205
Rvalue::Cast(
198206
kind @ (CastKind::IntToInt

0 commit comments

Comments
 (0)