Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Next Next commit
[mir-opt] Introduce a new flag to enable experimental/unsound mir opts
  • Loading branch information
wesleywiser committed Sep 27, 2020
commit b9d0ea95c8d87310262f6f6cb88c16f6d3d323cc
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-any-operand.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 works for any operand

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
2 changes: 1 addition & 1 deletion src/test/mir-opt/inline/inline-trait-method_2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z span_free_formats -Z mir-opt-level=3
// compile-flags: -Z span_free_formats -Z mir-opt-level=3 -Zunsound-mir-opts

// EMIT_MIR inline_trait_method_2.test2.Inline.after.mir
fn test2(x: &dyn X) -> bool {
Expand Down
207 changes: 111 additions & 96 deletions src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff

Large diffs are not rendered by default.

207 changes: 111 additions & 96 deletions src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/mir-opt/nrvo-simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Zmir-opt-level=1
// compile-flags: -Zmir-opt-level=1 -Zunsound-mir-opts

// EMIT_MIR nrvo_simple.nrvo.RenameReturnPlace.diff
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compile-flags: -Zunsound-mir-opts

fn map(x: Option<Box<()>>) -> Option<Box<()>> {
match x {
None => None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
+ // MIR for `map` after SimplifyLocals

fn map(_1: Option<Box<()>>) -> Option<Box<()>> {
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
- let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
- let mut _7: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:8: 3:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:31: 3:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:25: 6:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
- let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
- let mut _7: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
scope 1 {
debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
}

bb0: {
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:2: 6:2
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
+ // MIR for `map` after SimplifyLocals

fn map(_1: Option<Box<()>>) -> Option<Box<()>> {
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
- let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
- let mut _7: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:8: 3:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:31: 3:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:25: 6:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
- let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
- let mut _7: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
scope 1 {
debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
}

bb0: {
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:2: 6:2
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2
}
}

1 change: 1 addition & 0 deletions src/test/mir-opt/simplify_try.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// compile-flags: -Zunsound-mir-opts
// EMIT_MIR simplify_try.try_identity.SimplifyArmIdentity.diff
// EMIT_MIR simplify_try.try_identity.SimplifyBranchSame.after.mir
// EMIT_MIR simplify_try.try_identity.SimplifyLocals.after.mir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
+ // MIR for `try_identity` after DestinationPropagation

fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:7:17: 7:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:7:41: 7:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:8:9: 8:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:9:8: 9:9
scope 1 {
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:8:9: 8:10
}
scope 2 {
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15
scope 3 {
scope 7 {
debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
}
scope 8 {
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:14: 7:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
}
}
}
scope 4 {
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:8:13: 8:15
scope 5 {
}
}
Expand All @@ -40,33 +40,33 @@
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10
- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
- _4 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:8:9: 8:10
- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
- _4 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
- _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
+ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
+ _0 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ nop; // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
+ nop; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
+ _0 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
+ nop; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
+ nop; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
goto -> bb1; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ nop; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
goto -> bb1; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
}

bb1: {
- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
+ nop; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
+ nop; // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2
goto -> bb2; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
+ nop; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
+ nop; // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:10:1: 10:2
goto -> bb2; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
}

bb2: {
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
return; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
}
}

Loading