Skip to content

Commit ec87b99

Browse files
committed
Clarify the conditions on the aliasing section
1 parent 55de6fa commit ec87b99

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/aliasing.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ fn compute(input: &u32, output: &mut u32) {
3131
if *input > 5 {
3232
*output *= 2;
3333
}
34+
// remember that `output` will be `2` if `input > 10`
3435
}
3536
```
3637

3738
We would *like* to be able to optimize it to the following function:
3839

3940
```rust
4041
fn compute(input: &u32, output: &mut u32) {
41-
let cached_input = *input; // keep *input in a register
42+
let cached_input = *input; // keep `*input` in a register
4243
if cached_input > 10 {
43-
*output = 2; // x > 10 implies x > 5, so double and exit immediately
44+
// x > 10 implies x > 5, so remove the first if condition,
45+
// set it to `2`, and exit immediately
46+
*output = 2;
4447
} else if cached_input > 5 {
4548
*output *= 2;
4649
}

0 commit comments

Comments
 (0)