Skip to content

Commit ca2c2ac

Browse files
committed
Gate move elimination behind -Z mir-move-elimination
This flag also has the effect of disabling DestinationPropagation, which is already covered by move elimination.
1 parent a20834e commit ca2c2ac

5 files changed

Lines changed: 6 additions & 3 deletions

File tree

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ fn test_unstable_options_tracking_hash() {
848848
tracked!(min_function_alignment, Some(Align::EIGHT));
849849
tracked!(min_recursion_limit, Some(256));
850850
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
851+
tracked!(mir_move_elimination, true);
851852
tracked!(mir_opt_level, Some(4));
852853
tracked!(mir_preserve_ub, true);
853854
tracked!(move_size_limit, Some(4096));

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(super) struct DestinationPropagation;
153153

154154
impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
155155
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
156-
sess.mir_opt_level() >= 2
156+
sess.mir_opt_level() >= 2 && !sess.opts.unstable_opts.mir_move_elimination
157157
}
158158

159159
#[tracing::instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/move_elimination.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub(super) struct MoveElimination;
125125

126126
impl<'tcx> crate::MirPass<'tcx> for MoveElimination {
127127
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
128-
sess.mir_opt_level() >= 2
128+
sess.mir_opt_level() >= 2 && sess.opts.unstable_opts.mir_move_elimination
129129
}
130130

131131
#[tracing::instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/tail_copy_to_move.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(super) struct TailCopyToMove;
4040

4141
impl<'tcx> crate::MirPass<'tcx> for TailCopyToMove {
4242
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
43-
sess.mir_opt_level() >= 2
43+
sess.mir_opt_level() >= 2 && sess.opts.unstable_opts.mir_move_elimination
4444
}
4545

4646
#[tracing::instrument(level = "trace", skip(self, _tcx, body))]

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,8 @@ options! {
24952495
mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
24962496
"include extra comments in mir pretty printing, like line numbers and statement indices, \
24972497
details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
2498+
mir_move_elimination: bool = (false, parse_bool, [TRACKED],
2499+
"enable the experimental MIR move elimination pass (default: no)"),
24982500
mir_opt_bisect_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
24992501
"limit the number of MIR optimization pass executions (global across all bodies). \
25002502
Pass executions after this limit are skipped and reported. (default: no limit)"),

0 commit comments

Comments
 (0)