-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[StackColoring] Change the StackColoring logic + enables it to handle spills #143800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
I am willing to take a look, but for various reasons I won't be able to dig in for a couple of months (I am away from my work computers). Hope you can make progress without my eyeballs for now. Thanks. |
The cleanup commits look reasonable; please submit them separately. The IR representation of lifetimes has some pretty significant issues (see #45725 (comment) , #51838, #132085, #43674). Will this cause those issues to be exposed more frequently? |
Yes,
Here are my thoughts on the problems in general, I think there is 2 distinct issues: IR transformation moving accesses out of lifetime, causing UB: About the question, original question: |
Without it it can lead to crazy situtation, when passing a LiveRange* to a function expecting a const LiveRange& the LiveRange* is converted to bool and a new empty LiveRange is created.
…neInstructionElim
…+ deal with direct fallout
595d5af
to
f7ae304
Compare
After a bit of heuristics tuning, I got rid of the regression in average on code-size
|
Here is a patch set I have been working on to reduce stack usage.
It starts with a bunch if trivial NFC-like commits, that can be easily handled separately
Then a replacement of the StackColoring algorithm, with all the original analysis and assumption kept.
Finally changes to allow the new algo in StackColoring to operate on spill slots
I know that lifetime annotations are a mess, so I tried to not change any of the assumptions made by the old StackColoring.
here is some examples of the current stack coloring's shortcoming:
one of the int will be merged with the array, and thats it.
when all 4 ints could share the space with the array
The current StackColoring is not capable of re-using the same storage for all 3 of these arrays
Even if its the example given in the comments of StackColoring.
Both those issues are fixed by the Algorithm change
StackColoring had TODO's about this issue and handling spill slots at the same time as regular slots
This patch set adds 2 options used to do the testing.
-mllvm -new-stack-coloring, this swaps out the algorithm for stack-coloring.
-mllvm -merged-stack-coloring, this moves stack-coloring after regalloc instead of stack-slot-coloring
I have not yet updated tests because all of the work is behind options
and didn't added golden tests YET because the code has kept changing. But I obviously will add tests. before any merging.
Testing Done on this patch:
Benchmark results (mean):
Note: all benchmarks are done with release with assert build, on the llvm-test-suite
With max-candidates=unlimited, because it doesn't seem to have much impact on compile-time.
I suspect this is caused by some frequently accessed slot not being close to the sp,
leading to larger variants of the instruction being used. But I need to investigate
Note: The cleanup of the git history was only partial for now, its intended mostly help review.