You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rustc_mir_transform: Add a local value numbering pass, off by default.
This commit adds a local [value numbering] pass, which is intended to
eventually subsume constant and copy propagation. It's designed to detect
whether a value has been computed multiple times and replace such duplicate
computations with a reference to the originally-computed value. LLVM performs
this optimization, but it's limited because it doesn't have the ability to
reason about immutability of memory the way Rust MIR can. For example, this
pass optimizes [the following code]:
let s1: &S = ...;
let s2: &mut S = ...;
let mut sum = 0;
sum += s1.a + s1.b;
s2.a = 1;
sum += s1.a + s1.b;
into:
let s1: &S = ...;
let s2: &mut S = ...;
let mut sum = 0;
sum += s1.a + s1.b;
s2.a = 1;
sum += sum;
LLVM won't do this optimization because it can't prove that the assignment to a
field of `s2` doesn't mutate the fields of `s1`.
Because this pass is likely to have bugs and may be slow, I've turned it off by
default for now. I didn't notice any show-stopping bugs in the test suite, but
out of an abundance of caution I'm keeping it off.
Closes#91688.
[value numbering]: https://en.wikipedia.org/wiki/Value_numbering
[the following code]: https://rust.godbolt.org/z/7f6Gff7Ms
0 commit comments