# Rematerialization

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Rematerialization
> Markdown URL: https://mediated.wiki/source/Rematerialization.md
> Source: https://en.wikipedia.org/wiki/Rematerialization
> Source revision: 1326444078
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Compiler optimization technique}}
{{about|the compiler optimization|the Star Trek transporter technology|Transporter (Star Trek)}}

{{no footnotes|date=January 2016}}

In [computer science](/source/computer_science), '''rematerialization''' or '''remat''' is a [compiler optimization](/source/compiler_optimization) which saves time by recomputing a value instead of loading it from memory. It is typically tightly integrated with [register allocation](/source/register_allocation), where it is used as an alternative to [spilling](/source/register_spilling) registers to memory. It was conceived by [Gregory Chaitin](/source/Gregory_Chaitin), [Marc Auslander](/source/Marc_Auslander), [Ashok Chandra](/source/Ashok_Chandra), [John Cocke](/source/John_Cocke_(computer_scientist)), [Martin Hopkins](/source/Martin_Hopkins) and [Peter Markstein](/source/Peter_Markstein) and implemented in the Pl.8 compiler for the 801 Minicomputer in the late 1970s. Later improvements were made by [Preston Briggs](/source/Preston_Briggs), [Keith D. Cooper](/source/Keith_D._Cooper), and [Linda Torczon](/source/Linda_Torczon) in 1992.

Traditional optimizations such as [common subexpression elimination](/source/common_subexpression_elimination) and [loop invariant hoisting](/source/loop_invariant_hoisting) often focus on eliminating redundant computation. Since computation requires [CPU](/source/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](/source/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 &mdash; that is, when a register spill to memory would otherwise occur.

Rematerialization works by keeping track of the expression used to compute each variable, using the concept of [available expression](/source/available_expression)s. Sometimes the variables used to compute a value are modified, and so can no longer be used to rematerialize that value. The expression is then said to no longer be available. Other criteria must also be fulfilled, for example a maximum complexity on the expression used to rematerialize the value; it would do no good to rematerialize a value using a complex computation that takes more time than a load. Usually the expression must also have no [side effects](/source/side_effect_(computer_science)).

== External links ==
* Chaitin, Gregory, Marc Auslander, Ashok Chandra, John Cocke, Martin Hopkins, and Peter Markstein. "Register Allocation Via Coloring, Computer Languages, Vol. 6, No. 1, 1981, pp. 47-57"
* P. Briggs, K. D. Cooper, and L. Torczon. [https://dl.acm.org/doi/pdf/10.1145/143103.143143 Rematerialization]. ''Proceedings of the SIGPLAN 92 Conference on Programming Language Design and Implementation'', SIGPLAN Notices 27(7), p.311-321. July 1992.
* Mukta Punjabi. [https://web.archive.org/web/20050428005246/http://gcc.fyxm.net/summit/2004/Register%20Rematerialization.pdf Register Rematerialization in GCC]. Discusses [gcc](/source/GNU_Compiler_Collection)'s implementation of rematerialization.

{{Compiler optimizations}}

Category:Compiler optimizations

---
Adapted from the Wikipedia article [Rematerialization](https://en.wikipedia.org/wiki/Rematerialization) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Rematerialization?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
