Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
merge-locals pass #1334
This optimizes the situation described in #1331. Namely, when x is copied into y, then on subsequent gets of x we could use y instead, and vice versa, as their value is equal. Specifically, this seems to get rid of the definite overlap in the live ranges of x and y, as removing it allows coalesce-locals to merge them. The pass therefore does nothing if the live range of y ends there anyhow.
The danger here is that we may extend the live range so that it causes more conflicts with other things, so this is a heuristic, but I've tested it on every codebase I can find and it always produces a net win, even on one I saw a 0.4% reduction of code size, which surprised me.
This is a fairly slow pass, because it uses LocalGraph which isn't much optimized. This PR includes a minor optimization for it, but we should rewrite it. Meanwhile this is just enabled in -O3 and -Oz.
This PR also includes some fuzzing improvements, to better test stuff like this.
Thinking a bit more about this, maybe we should check on more code. @dcodeIO, can you maybe try more code from your compiler? I've checked on the one testcase from you, plus a bunch from emscripten, but more testing would be good (since this is more of a heuristic than a guarantee). By testing, I mean to run it on some code and see if it improves things or not, say by measuring the binary size, or the output of
This new pass is a default optimization in
The diff with
Ok, thanks, I guess we've tested this all we can. All signs look positive, so I'll merge this. We should optimize the pass for speed eventually, and turn it on in