Skip to content

Commit 65389df

Browse files
committed
Expand on why we swap StorageDead
1 parent df05775 commit 65389df

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

compiler/rustc_mir/src/transform/instcombine.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,21 @@ impl OptimizationFinder<'b, 'tcx> {
288288
}
289289
}
290290

291-
// We need to make sure that the Ne we are going to insert comes before the
292-
// StorageDeads so we want to swap the StorageDead closest to Eq with Ne.
291+
// Recall that we are optimizing a sequence that looks like
292+
// this:
293+
// _4 = Eq(move _5, move _6);
294+
// StorageDead(_5);
295+
// StorageDead(_6);
296+
// _3 = Not(move _4);
297+
//
298+
// If we do a naive replace of Not -> Ne, we up with this:
299+
// StorageDead(_5);
300+
// StorageDead(_6);
301+
// _3 = Ne(move _5, move _6);
302+
//
303+
// Notice that `_5` and `_6` are marked dead before being used.
304+
// To combat this we want to swap Ne with the StorageDead
305+
// closest to Eq, i.e `StorageDead(_5)` in this example.
293306
let storage_dead_to_swap =
294307
seen_storage_deads.last().map(|(_, idx)| *idx);
295308

0 commit comments

Comments
 (0)