This isn't special - almost every compiler pass is a heuristic approximation of an NP-hard problem (hello register allocation, instruction scheduling).
A small nit. The problem of assigning registers to values (in SSA form) has a single pass optimal solution.
Adding other complexities such as when to spill, and the possibility of reordering computation to reduce the number of registers makes the problem more difficult.
All of which makes me wonder how many of the "NP-hard problems" are in fact easier problems that a covering general case is hard
> The problem of assigning registers to values (in SSA form) has a single pass optimal solution
I knew someone would comment this because hn is always "well akshually...". But the parenthetical is doing all the work in this "nit". Yes coloring chordal graphs is polynomial but real compilers don't do register allocation on SSA form. Spilling and spitting break chordal form.
The HotSpot C1 compiler allocates on SSA form [0], so does libfirm [1], I think the Android Runtime does [2], Go does [3], and so does Cranelift [4]. And this compiler for Intel GPUs does too [5].
Adding other complexities such as when to spill, and the possibility of reordering computation to reduce the number of registers makes the problem more difficult.
All of which makes me wonder how many of the "NP-hard problems" are in fact easier problems that a covering general case is hard