Skip to content

Commit 0eb297d

Browse files
committed
Fix up merge_from_succ.
This function has a variable `changed` that is erroneously used for two related-but-different purpose: - to detect if the current element has changed; - to detect if any elements have changed. As a result, its use for the first purpose is broken, because if any prior element changed then the code always thinks the current element has changed. This is only a performance bug, not a correctness bug, because we frequently end up calling `assign_unpacked` unnecessarily to overwrite the element with itself. This commit adds `any_changed` to correctly distinguish between the two purposes. This is a small perf win for some benchmarks.
1 parent eed12bc commit 0eb297d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/librustc_passes/liveness.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
822822
return false;
823823
}
824824

825-
let mut changed = false;
825+
let mut any_changed = false;
826826
self.indices2(ln, succ_ln, |this, idx, succ_idx| {
827+
let mut changed = false;
827828
let mut rwu = this.rwu_table.get(idx);
828829
let succ_rwu = this.rwu_table.get(succ_idx);
829830
if succ_rwu.reader.is_valid() && !rwu.reader.is_valid() {
@@ -843,6 +844,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
843844

844845
if changed {
845846
this.rwu_table.assign_unpacked(idx, rwu);
847+
any_changed = true;
846848
}
847849
});
848850

@@ -851,9 +853,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
851853
ln,
852854
self.ln_str(succ_ln),
853855
first_merge,
854-
changed
856+
any_changed
855857
);
856-
return changed;
858+
return any_changed;
857859
}
858860

859861
// Indicates that a local variable was *defined*; we know that no

0 commit comments

Comments
 (0)