-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[StackColoring] Incorrect slot merging due to stackcoloring-lifetime-start-on-first-use #132085
Comments
Where is this requirement specified? I don't believe that overlapping lifetimes are intended to guarantee that the addresses differ. They should be consistently observed as equal or not equal at runtime, but I believe both outcomes are legal. (Similar to how e.g. two different functions may or may not compare equal.) |
LangRef guarantees that pointers returned by alloca are unique, so if any, the Since the entire purpose of lifetime intrinsics is for them to be sufficient Step back for a moment and consider the same function without any lifetime Alive2 agrees that with overlapping lifetimes addresses must differ: |
Could you please point me to where LangRef guarantees that allocas can never have the same address? I couldn't find wording to that effect, and as you say, the presence of lifetime intrinsics would certainly make such a requirement incorrect.
I don't follow the example. If you inline the function in the issue description the lifetimes will be placed differently (the %a lifetime will not end early). But in any case, that still assumes that "equal" and "not equal" cannot be both valid outcomes.
When it comes to address identity, I would not blindly trust alive2 output. I've encountered may bugs it has in this particular area. |
Do I understand correctly, that you are claiming that in the case without define i1 @g() {
%a = alloca ptr
%b = alloca ptr
%c = icmp eq ptr %a, %b
ret i1 %c
} I take it as a fundamental that allocated objects that are live at the same I don't understand why equal would be a valid outcome, or how would C, C++, or Semantics section for |
My general assumption here was that lifetime intrinsics are an optimization hint rather than a specification of when exactly allocation/deallocation must occur, so that it's possible to shrink the lifetime based on usage (e.g. by "sinking" the allocation point, as happens in the example from the issue description). For your simplified example from the last comment, I don't think that can return true as both allocas are used in the icmp. Anyway, my assumption about how this is supposed to work is probably wrong. In any case, we should explicitly document the semantics in LangRef. |
The semantics of lifetime intrinsics is a longstanding issue; see #45725. At first glance, this is basically a duplicate. |
A simpler demonstration of the issue, this time with proper nesting of lifetimes: define i32 @main() {
entry:
%a = alloca [1000 x i8]
%b = alloca [1000 x i8]
call void @llvm.lifetime.start.p0(i64 1000, ptr %a)
call void @llvm.lifetime.start.p0(i64 1000, ptr %b)
call void @llvm.lifetime.end.p0(i64 1000, ptr %b)
%0 = icmp eq ptr %a, %b
call void @llvm.lifetime.end.p0(i64 1000, ptr %a)
%1 = zext i1 %0 to i32
ret i32 %1
} $ lli-21 -stackcoloring-lifetime-start-on-first-use=0 a.ll; echo $?
0
$ lli-21 -stackcoloring-lifetime-start-on-first-use=1 a.ll; echo $?
1 |
Whether or not two variables can be equal has to be tied to some clear property of the program. Maybe it's not lifetime intrinsics, but then what is it? The answer cannot be "look at how the variables are used" because there are optimizations that change how the variables are used, and if the syntactic position of the first and last use was somehow semantically relevant, then those optimizations would be wrong. |
In the program below, the allocation
a
and allocationb
have overlappinglive ranges, so it should be impossible to observe them having the same
address. Nevertheless StackColoring merges stack slots for
a
andb
. Thisis incorrect since addresses of those allocations might be captured by
g
.This is caused by stackcoloring-lifetime-start-on-first-use (the default) where
stack coloring shrinks live range towards first use.
The text was updated successfully, but these errors were encountered: