SCC-Based Value Numbering

Value numbering is an optimization that assigns numbers to values in such a way that two values are assigned the same number if and only if the compiler can prove they are equal. When this optimization discovers two computations that produce the same value, it can (under certain circumstances) eliminate one of them. There are two competing techniques for proving equivalences: hashing and partitioning. The hashing techniques are easy to understand and implement, and they can easily handle constant folding and algebraic identities (i.e., x+0 = x). Their prime drawback is that they are not global techniques. The partitioning techniques are global, but they cannot easily handle constant folding and algebraic identities. As a result of their shortcomings, both of these techniques can fail to discover some crucial equivalences. In this paper, we describe a new technique for assigning value numbers that combines the advantages of both techniques { it is easy to understand and implement; it can easily handle constant folding and algebraic identities, and it is global. We refer to this new technique as SCC-based value numbering because it is centered around the strongly connected components of the static single assignment graph. We will prove that our technique always nds at least as many equivalences as hashing or partitioning, and experimentally compare the improvements made in the context of an optimizing compiler.