Unofficial Hacker News companion — get notified on comment replies, and more.

ML compiler eng, your job is NP-hard (opens external site)

35 points by gmays 7 days ago | ianbarber.blog | 9 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (3)

  1. The linear scan register allocator is the optimal solution and it is used widely even on non-SSA form repreststions of code. My memory says pretty much every JIT compiler and LLVM. People use it because it is good, fast, and easy to adapt to the challenges of the task that don't show up in theory.

    I tried to understand the NP-completeness proof at one point. I learned the NP-completeness did not come from graph coloring but from program transformations like spilling and exactly how the problem had been framed.

    It is not the case that spilling and splitting necessarily break SSA-form. It is the case that any program transformation messes up an explicit register interference graph. Which makes Chatain's register allocation by graph coloring stupidly expensive in the case of code transformations.

    Having used that algorithm I really dislike it in practice. It makes everything harder all so an approximate solution can be used for part of the problem that has a cheap exact solution.

    But hey it looks simple.

    To address your original point. Most compiler algorithms are heuristics because even an O(N^2) algorithm is typically too expensive in practice.

    In general when writing a compiler the difference between O(N^3) time and exponential time of a NP-complete algorithm is a don't care. They are just too expensive.

    Replies (2)
    1. > LLVM

      LLVM does not use linear scan