Rematerialization

In computer science, rematerialization or remat is a compiler optimization which saves time by recomputing a value instead of loading it from memory.

It was conceived by Gregory Chaitin, Marc Auslander, Ashok Chandra, John Cocke, Martin Hopkins and Peter Markstein and implemented in the Pl.8 compiler for the 801 Minicomputer in the late 1970s.

Since computation requires CPU cycles, this is usually a good thing, but it has the potentially devastating side effect that it can increase the live ranges of variables and create many new variables, resulting in spills during register allocation.

Rematerialization is nearly the opposite: it decreases register pressure by increasing the amount of CPU computation.

To avoid adding more computation time than necessary, rematerialization is done only when the compiler can be confident that it will be of benefit — that is, when a register spill to memory would otherwise occur.