# Liveness: avoid emitting unused instructions or marking their operands as used · gitcafe/zig

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

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

Visibility: public

Requested revision: 407dc6eee4660bb0744c55f4565be77501ec7d37

Requested commit: 407dc6eee4660bb0744c55f4565be77501ec7d37

Commit: 407dc6eee4660bb0744c55f4565be77501ec7d37

Tree: 8e58be56dea4c1f318b0cb57ea7d4ab9d85076a7

Author: mlugg

Committer: mlugg

## Message

```
Liveness: avoid emitting unused instructions or marking their operands as used

Backends want to avoid emitting unused instructions which do not have
side effects: to that end, they all have `Liveness.isUnused` checks for
many instructions. However, checking this in the backends avoids a lot
of potential optimizations. For instance, if a nested field is loaded,
then the first field access would still be emitted, since its result is
used by the next access (which is then unreferenced).

To elide more instructions, Liveness can track this data instead. For
operands which do not have to be lowered (i.e. are not side effecting
and are not something special like `arg), Liveness can ignore their
operand usages, and push the unused information further up, potentially
marking many more instructions as unreferenced.

In doing this, I also uncovered a bug in the LLVM backend relating to
discarding the result of `@cVaArg`, which this change fixes. A behaviour
test has been added to cover it.

```

## Parents

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

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