Global value numbering (GVN) is a compiler optimization based on the SSA intermediate representation. It sometimes helps eliminate redundant code that common subexpression elimination (CSE) does not. At the same time, however, CSE may eliminate code that GVN does not, so both are often found in modern compilers. Global value numbering is distinct from local value numbering in that the value-number mappings hold across basic block boundaries as well, and different algorithms are used to compute the mappings.
Global value numbering works by assigning a value number to variables and expressions. To those variables and expressions which are provably equivalent, the same value number is assigned. For instance, in the following code:
w := 3 x := 3 y := x + 4 z := w + 4a good GVN routine would assign the same value number to w
and x
, and the same value number to y
and z
. For instance, the map would constitute an optimal value-number mapping for this block. Using this information, the previous code fragment may be safely transformed into:
Depending on the code following this fragment, copy propagation may be able to remove the assignments to x
and to z
The reason that GVN is sometimes more powerful than CSE comes from the fact that CSE matches lexically identical expressions whereas the GVN tries to determine an underlying equivalence. For instance, in the code:
a := c × d e := c f := e × dCSE would not eliminate the recomputation assigned to f
, but even a poor GVN algorithm should discover and eliminate this redundancy.
SSA form is required to perform GVN so that false variable name-value name mappings are not created.
Famous quotes containing the words global and/or numbering:
“The Sage of Toronto ... spent several decades marveling at the numerous freedoms created by a global village instantly and effortlessly accessible to all. Villages, unlike towns, have always been ruled by conformism, isolation, petty surveillance, boredom and repetitive malicious gossip about the same families. Which is a precise enough description of the global spectacles present vulgarity.”
—Guy Debord (b. 1931)
“The task he undertakes
Is numbering sands and drinking oceans dry.”
—William Shakespeare (15641616)