[llvm] [StackColoring] Change the StackColoring logic + enables it to handle spills (PR #143800)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 12 03:48:44 PDT 2025


Ralender wrote:

> The cleanup commits look reasonable; please submit them separately.

Yes,
> 
> The IR representation of lifetimes has some pretty significant issues (see [#45725 (comment)](https://github.com/llvm/llvm-project/issues/45725#issuecomment-1537597333) , #51838, #132085, #43674). Will this cause those issues to be exposed more frequently?

Here are my thoughts on the problems in general, I think there is 2 distinct issues:
Pointer comparisons self-consistency:
The only viable solution I see is tagging allocas, that need to stay distinct from each other and ensuring alias analysis and StackColoring respect it. and whenever the IR folds a icmp based on distinct provenance, it tags the allocas as distinct from each other. this keeps folding icmp simple. and it would not be legal to remove a tag from an alloca under any circumstances. I/We need to experiment, but it may not have much of negative impact.

IR transformation moving accesses out of lifetime, causing UB:
I have only seen for loads, so maybe loads outside of lifetime could be defined as poison instead of UB, as has been proposed.
maybe an other solution is to say that lifetime annotation only have meaning for captures, and accesses outside of it are legal. alias analysis could still assume that a call outside of lifetime cannot access an escaped pointer, but potential load and/or store outside of lifetime would cause extension of the lifetime. Captures scopes cannot be changed by optimizations and everything else should analyzable even if. we may need to be pessimist when multiple objects could be accessed by a load.

About the question, original question:
The old and new StackColoring always agree on whether 2 slots can overlap or not.
I checked it at some point by having an assert during development (it was removed since).
That said, the new algorithm reduces stack space but getting more overlaps between slots.
So some slots that would not have overlapped with the old algo because of different decisions may overlap now.
Spills are unaffected by all the lifetime issues.



https://github.com/llvm/llvm-project/pull/143800


More information about the llvm-commits mailing list