@@ -149,15 +149,18 @@ pub struct DestinationPropagation;
149
149
150
150
impl < ' tcx > MirPass < ' tcx > for DestinationPropagation {
151
151
fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
152
- // For now, only run at MIR opt level 3. Two things need to be changed before this can be
153
- // turned on by default:
154
- // 1. Because of the overeager removal of storage statements, this can cause stack space
155
- // regressions. This opt is not the place to fix this though, it's a more general
156
- // problem in MIR.
157
- // 2. Despite being an overall perf improvement, this still causes a 30% regression in
158
- // keccak. We can temporarily fix this by bounding function size, but in the long term
159
- // we should fix this by being smarter about invalidating analysis results.
160
- sess. mir_opt_level ( ) >= 3
152
+ // This pass is technically enabled at MIR opt level 2, but in a reduced form.
153
+ // At MIR opt level 2, we run a single round, and at MIR opt level 3 or greater we keep
154
+ // running rounds until we reach a fixed point. Based on experimentation with the rustc
155
+ // benchmark suite, the majority of the benefit from this pass comes from the first round,
156
+ // though on some code it continues to find optimizations for >10 rounds.
157
+ // It may be possible to enable multiple rounds at MIR opt level 2 by being more careful
158
+ // about invalidating analysis results.
159
+ //
160
+ // Note that due to overeager removal of storage statements, this pass (particularly at MIR
161
+ // opt level 3), can cause stack space regressions. This opt is not the place to fix this
162
+ // though, it's a more general problem in MIR.
163
+ sess. mir_opt_level ( ) >= 2
161
164
}
162
165
163
166
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
@@ -236,6 +239,11 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
236
239
round_count += 1 ;
237
240
238
241
apply_merges ( body, tcx, & merges, & merged_locals) ;
242
+
243
+ // At MIR opt level 2, we only run one iteration.
244
+ if tcx. sess . mir_opt_level ( ) < 3 {
245
+ break ;
246
+ }
239
247
}
240
248
241
249
trace ! ( round_count) ;
0 commit comments