Dead Assignments and Observable Effects

Delete a computation only when its result and its evaluation are both outside the program’s observable behavior.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Walk backward from demanded results
  2. A value can be dead while its computation matters

Walk backward from demanded results

In SSA, start with instructions required for output, control or other observable effects. Mark the definitions supplying their operands, then repeat through those definitions’ own inputs. An unmarked pure instruction can be removed. This handles chains where a computed value was used only by another computation whose result is never used. The procedure still needs an account of which control operations keep necessary blocks reachable.

A value can be dead while its computation matters

An unused integer addition can often disappear. A volatile read, logging operation or possible trap can remain observable even if its result has no consumers. The answer depends on the language’s semantics and compiler IR flags. Liveness determines where values may be needed. Translation validation can check whether a particular local rewrite preserves the modeled effects.[1][2]

References

  1. Andrew C. Myers, Cornell CS 4120: Compiler Course Notes ↩
  2. LLVM Project, LLVM Language Reference Manual ↩