diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-02 14:40:54 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-02 14:40:54 -0700 |
| commit | b33647231e20e2dc155beb2c8fe721f952d67a54 (patch) | |
| tree | 7d28d6b28b4aa519680456e2e47cb4cc48eaf077 /chapter10a/README.md | |
| parent | 1e2ebb397cbbca1a7d2fd35052c3b90a47bb5733 (diff) | |
| download | Simple-b33647231e20e2dc155beb2c8fe721f952d67a54.tar.gz Simple-b33647231e20e2dc155beb2c8fe721f952d67a54.zip | |
ch10a README
Diffstat (limited to 'chapter10a/README.md')
| -rw-r--r-- | chapter10a/README.md | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/chapter10a/README.md b/chapter10a/README.md index 6f51df28..968180b5 100644 --- a/chapter10a/README.md +++ b/chapter10a/README.md @@ -271,10 +271,28 @@ To enable this behaviour, we make the following enhancements. ## Local memory optimizations A load immediately following a store to the **same pointer and field** can use -the stored value. A store immediately following another store to the same -address can discard the earlier store when no other user needs it. Both the -pointer and field checks matter: two different fields of one object are -different addresses, as are the same fields of two different objects. +the stored value. We just wrote `arg` into `p.x`, so reading it back needs no +memory access: + +```java +struct Box { int x; } +Box p = new Box; +p.x = arg; +return p.x; // Can return arg directly. +``` + +| Before: read back the stored value | After: use the value directly | +|---|---| +|  |  | + +Return's result input changes from the Load to `arg`, and the unused Load +disappears. Return still consumes the Store's memory, so the write is retained. + +A store immediately following another store to the same address can also +discard the earlier store when no other user needs it. That separate rewrite +can remove the zero-initialization store still shown above. Both the pointer +and field checks matter: two different fields of one object are different +addresses, as are the same fields of two different objects. A load can also move up through a memory Phi. This extends [Chapter 5's push-through-Phi optimization](../chapter05/README.md#pushing-addition-up-through-a-phi): |
