Skip to content
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

[mir-opt] Introduce a new flag to enable experimental/unsound mir opts #76899

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion compiler/rustc_mir/src/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub struct CopyPropagation;

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

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
`hir,typed` (HIR with types for each node),
`hir-tree` (dump the raw HIR),
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
"enable unsound and buggy MIR optimizations (default: no)"),
unstable_options: bool = (false, parse_bool, [UNTRACKED],
"adds unstable command line options to rustc interface (default: no)"),
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
1 change: 1 addition & 0 deletions src/test/mir-opt/copy_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// compile-flags: -Zunsound-mir-opts
// EMIT_MIR copy_propagation.test.CopyPropagation.diff

fn test(x: u32) -> u32 {
Expand Down
18 changes: 9 additions & 9 deletions src/test/mir-opt/copy_propagation.test.CopyPropagation.diff
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
+ // MIR for `test` after CopyPropagation

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

bb0: {
nop; // scope 0 at $DIR/copy_propagation.rs:4:9: 4:10
_0 = _1; // scope 0 at $DIR/copy_propagation.rs:4:13: 4:14
nop; // scope 1 at $DIR/copy_propagation.rs:5:5: 5:6
nop; // scope 0 at $DIR/copy_propagation.rs:6:1: 6:2
return; // scope 0 at $DIR/copy_propagation.rs:6:2: 6:2
nop; // scope 0 at $DIR/copy_propagation.rs:5:9: 5:10
_0 = _1; // scope 0 at $DIR/copy_propagation.rs:5:13: 5:14
nop; // scope 1 at $DIR/copy_propagation.rs:6:5: 6:6
nop; // scope 0 at $DIR/copy_propagation.rs:7:1: 7:2
return; // scope 0 at $DIR/copy_propagation.rs:7:2: 7:2
}
}

2 changes: 1 addition & 1 deletion src/test/mir-opt/early_otherwise_branch_68867.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ignore-tidy-linelength
// compile-flags: -Z mir-opt-level=3
// compile-flags: -Z mir-opt-level=3 -Zunsound-mir-opts

// example from #68867
type CSSFloat = f32;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/inline/inline-closure-borrows-arg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z span_free_formats
// compile-flags: -Z span_free_formats -Zunsound-mir-opts

// Tests that MIR inliner can handle closure arguments,
// even when (#45894)
Expand Down
28 changes: 18 additions & 10 deletions src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ fn bar() -> bool {
let mut _0: bool; // return place in scope 0 at $DIR/inline-any-operand.rs:10:13: 10:17
let _1: fn(i32, i32) -> bool {foo}; // in scope 0 at $DIR/inline-any-operand.rs:11:9: 11:10
let mut _2: fn(i32, i32) -> bool {foo}; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:6
let mut _3: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13
let mut _4: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13
let mut _5: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13
let mut _6: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13
scope 1 {
debug f => _1; // in scope 1 at $DIR/inline-any-operand.rs:11:9: 11:10
scope 2 {
debug x => _3; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9
debug y => _4; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17
debug x => _5; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9
debug y => _6; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17
let mut _3: i32; // in scope 2 at $DIR/inline-any-operand.rs:12:5: 12:13
let mut _4: i32; // in scope 2 at $DIR/inline-any-operand.rs:12:5: 12:13
}
}

Expand All @@ -22,13 +24,19 @@ fn bar() -> bool {
// + literal: Const { ty: fn(i32, i32) -> bool {foo}, val: Value(Scalar(<ZST>)) }
StorageLive(_2); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6
_2 = _1; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6
StorageLive(_3); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
_3 = const 1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageLive(_4); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
_4 = const -1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageLive(_5); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
_5 = const 1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageLive(_6); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
_6 = const -1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageLive(_3); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6
_3 = _5; // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6
StorageLive(_4); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11
_4 = _6; // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11
_0 = Eq(move _3, move _4); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:11
StorageDead(_4); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageDead(_3); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageDead(_4); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11
StorageDead(_3); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11
StorageDead(_6); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageDead(_5); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13
StorageDead(_2); // scope 1 at $DIR/inline-any-operand.rs:12:12: 12:13
StorageDead(_1); // scope 0 at $DIR/inline-any-operand.rs:13:1: 13:2
return; // scope 0 at $DIR/inline-any-operand.rs:13:2: 13:2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn test2(_1: &dyn X) -> bool {
let mut _3: &dyn X; // in scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11
scope 1 {
debug x => _2; // in scope 1 at $DIR/inline-trait-method_2.rs:9:9: 9:10
let mut _4: &dyn X; // in scope 1 at $DIR/inline-trait-method_2.rs:5:5: 5:12
}

bb0: {
Expand All @@ -15,13 +16,16 @@ fn test2(_1: &dyn X) -> bool {
_3 = &(*_1); // scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11
_2 = move _3 as &dyn X (Pointer(Unsize)); // scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11
StorageDead(_3); // scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11
_0 = <dyn X as X>::y(move _2) -> bb1; // scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:10
StorageLive(_4); // scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:6
_4 = _2; // scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:6
_0 = <dyn X as X>::y(move _4) -> bb1; // scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:10
// mir::Constant
// + span: $DIR/inline-trait-method_2.rs:10:7: 10:8
// + literal: Const { ty: for<'r> fn(&'r dyn X) -> bool {<dyn X as X>::y}, val: Value(Scalar(<ZST>)) }
}

bb1: {
StorageDead(_4); // scope 1 at $DIR/inline-trait-method_2.rs:10:9: 10:10
StorageDead(_2); // scope 0 at $DIR/inline-trait-method_2.rs:5:11: 5:12
return; // scope 0 at $DIR/inline-trait-method_2.rs:6:2: 6:2
}
Expand Down
Loading