# stage2: Be more strict about eliding loads · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/8f3880074fb76871d9a4f35d1f72d0304ac5b404)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 8f3880074fb76871d9a4f35d1f72d0304ac5b404

Requested commit: 8f3880074fb76871d9a4f35d1f72d0304ac5b404

Commit: 8f3880074fb76871d9a4f35d1f72d0304ac5b404

Tree: f9d2cce5de2ef4080766064f853a9f0793ab5696

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

```
stage2: Be more strict about eliding loads

This change makes any of the `*_val` instructions check whether it's
safe to elide copies for by-ref types rather than performing this
elision blindly.

AIR instructions fixed:
 - .array_elem_val
 - .struct_field_val
 - .unwrap_errunion_payload
 - .try
 - .optional_payload

These now all respect value semantics, as expected.

P.S. Thanks to Andrew for the new way to approach this. Many of the
lines here are from his recommended change, which comes with the
significant advantage that loads are now as small as the intervening
memory access allows.

Co-authored by: Andrew Kelley <andrew@ziglang.org>

```

## Parents

- [ff699722da1f2df3e521c92cebe71c50910594d3](https://git.cafe/gitcafe/zig/commit/ff699722da1f2df3e521c92cebe71c50910594d3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/8f3880074fb76871d9a4f35d1f72d0304ac5b404?format=markdown)
