Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b9d0ea9

Browse files
committed
[mir-opt] Introduce a new flag to enable experimental/unsound mir opts
1 parent 7f7a1cb commit b9d0ea9

20 files changed

+397
-359
lines changed

compiler/rustc_mir/src/transform/copy_prop.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ pub struct CopyPropagation;
3131

3232
impl<'tcx> MirPass<'tcx> for CopyPropagation {
3333
fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut Body<'tcx>) {
34+
let opts = &tcx.sess.opts.debugging_opts;
3435
// We only run when the MIR optimization level is > 1.
3536
// This avoids a slow pass, and messing up debug info.
36-
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
37+
// FIXME(76740): This optimization is buggy and can cause unsoundness.
38+
if opts.mir_opt_level <= 1 || !opts.unsound_mir_opts {
3739
return;
3840
}
3941

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11151115
`hir,typed` (HIR with types for each node),
11161116
`hir-tree` (dump the raw HIR),
11171117
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
1118+
unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
1119+
"enable unsound and buggy MIR optimizations (default: no)"),
11181120
unstable_options: bool = (false, parse_bool, [UNTRACKED],
11191121
"adds unstable command line options to rustc interface (default: no)"),
11201122
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],

src/test/mir-opt/copy_propagation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: -Zunsound-mir-opts
12
// EMIT_MIR copy_propagation.test.CopyPropagation.diff
23

34
fn test(x: u32) -> u32 {

src/test/mir-opt/copy_propagation.test.CopyPropagation.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
+ // MIR for `test` after CopyPropagation
33

44
fn test(_1: u32) -> u32 {
5-
debug x => _1; // in scope 0 at $DIR/copy_propagation.rs:3:9: 3:10
6-
let mut _0: u32; // return place in scope 0 at $DIR/copy_propagation.rs:3:20: 3:23
7-
let _2: u32; // in scope 0 at $DIR/copy_propagation.rs:4:9: 4:10
5+
debug x => _1; // in scope 0 at $DIR/copy_propagation.rs:4:9: 4:10
6+
let mut _0: u32; // return place in scope 0 at $DIR/copy_propagation.rs:4:20: 4:23
7+
let _2: u32; // in scope 0 at $DIR/copy_propagation.rs:5:9: 5:10
88
scope 1 {
9-
debug y => _0; // in scope 1 at $DIR/copy_propagation.rs:4:9: 4:10
9+
debug y => _0; // in scope 1 at $DIR/copy_propagation.rs:5:9: 5:10
1010
}
1111

1212
bb0: {
13-
nop; // scope 0 at $DIR/copy_propagation.rs:4:9: 4:10
14-
_0 = _1; // scope 0 at $DIR/copy_propagation.rs:4:13: 4:14
15-
nop; // scope 1 at $DIR/copy_propagation.rs:5:5: 5:6
16-
nop; // scope 0 at $DIR/copy_propagation.rs:6:1: 6:2
17-
return; // scope 0 at $DIR/copy_propagation.rs:6:2: 6:2
13+
nop; // scope 0 at $DIR/copy_propagation.rs:5:9: 5:10
14+
_0 = _1; // scope 0 at $DIR/copy_propagation.rs:5:13: 5:14
15+
nop; // scope 1 at $DIR/copy_propagation.rs:6:5: 6:6
16+
nop; // scope 0 at $DIR/copy_propagation.rs:7:1: 7:2
17+
return; // scope 0 at $DIR/copy_propagation.rs:7:2: 7:2
1818
}
1919
}
2020

src/test/mir-opt/early_otherwise_branch_68867.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-linelength
2-
// compile-flags: -Z mir-opt-level=3
2+
// compile-flags: -Z mir-opt-level=3 -Zunsound-mir-opts
33

44
// example from #68867
55
type CSSFloat = f32;

src/test/mir-opt/inline/inline-any-operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z span_free_formats
1+
// compile-flags: -Z span_free_formats -Zunsound-mir-opts
22

33
// Tests that MIR inliner works for any operand
44

src/test/mir-opt/inline/inline-closure-borrows-arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z span_free_formats
1+
// compile-flags: -Z span_free_formats -Zunsound-mir-opts
22

33
// Tests that MIR inliner can handle closure arguments,
44
// even when (#45894)

src/test/mir-opt/inline/inline-trait-method_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z span_free_formats -Z mir-opt-level=3
1+
// compile-flags: -Z span_free_formats -Z mir-opt-level=3 -Zunsound-mir-opts
22

33
// EMIT_MIR inline_trait_method_2.test2.Inline.after.mir
44
fn test2(x: &dyn X) -> bool {

src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff

Lines changed: 111 additions & 96 deletions
Large diffs are not rendered by default.

src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff

Lines changed: 111 additions & 96 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)