Krzysztof Parzyszek
2012-Dec-26 20:28 UTC
[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
On 12/25/2012 1:31 PM, Alexey Samsonov wrote:> > Ok, suppose you have the following code: > BB1: > llvm.lifetime.start(%a) > store to %a > llvm.lifetime.end(%a) > br %BB2 > > BB2: > <some code> > br %BB1 > > If you remove the first "llvm.lifetime.start", then when you enter > %BB1 for the second time, your "store to %a" can be considered invalid, > as you've already called llvm.lifetime.end for this variable.The llvm.lifetime.end(%a) in your example is invalid, according to the lang ref: "This intrinsic indicates that after this point in the code, the value of the memory pointed to by ptr is dead. This means that it is known to never be used and has an undefined value. Any stores into the memory object following this intrinsic may be removed as dead." If you can re-enter the block with a still-defined value of %a, then it's not "known to never be used". -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof Parzyszek
2012-Dec-26 20:34 UTC
[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
On 12/26/2012 2:28 PM, Krzysztof Parzyszek wrote:> > The llvm.lifetime.end(%a) in your example is invalid, according to the > lang ref:Correction: it's not invalid, but if the value that %a points to is indeed never used after the store (as the lifetime.end intrinsic would indicate), then the store was dead from the beginning. Deleting the lifetime.start(%a) wouldn't have any ill effect in that case. I'm not sure if that's what the author intended though. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof Parzyszek
2012-Dec-26 20:41 UTC
[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
Also, it's not clear to me what "the value of the memory pointed to by %a" means if %a comes from a phi node. I guess my interpretation may be wrong, but I don't feel comfortable with any interpretation that I can think of at the moment. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Nick Lewycky
2012-Dec-26 21:38 UTC
[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
On 12/26/2012 12:28 PM, Krzysztof Parzyszek wrote:> On 12/25/2012 1:31 PM, Alexey Samsonov wrote: >> >> Ok, suppose you have the following code: >> BB1: >> llvm.lifetime.start(%a) >> store to %a >> llvm.lifetime.end(%a) >> br %BB2 >> >> BB2: >> <some code> >> br %BB1 >> >> If you remove the first "llvm.lifetime.start", then when you enter >> %BB1 for the second time, your "store to %a" can be considered invalid, >> as you've already called llvm.lifetime.end for this variable. > > The llvm.lifetime.end(%a) in your example is invalid, according to the > lang ref: > > "This intrinsic indicates that after this point in the code, the value > of the memory pointed to by ptr is dead. This means that it is known to > never be used and has an undefined value. Any stores into the memory > object following this intrinsic may be removed as dead." > > If you can re-enter the block with a still-defined value of %a, then > it's not "known to never be used".The intention is that if you have a loop, you could mark the memory lifetime.end at the end of the loop, and operations on the next run of the loop would see 'undef' there -- at least until you call lifetime.start. Of course you can re-start memory that's been ended... if that isn't clear in the langref, please fix. Nick
Krzysztof Parzyszek
2012-Dec-26 22:37 UTC
[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
On 12/26/2012 3:38 PM, Nick Lewycky wrote:> > Of course you can re-start memory that's been ended... if that isn't > clear in the langref, please fix.There are several things that aren't clear (at least when I read it). Case 1: block: %a = phi i32* ..., [ %a.next, %block ] llvm.lifetime.begin(4, %a) ... llvm.lifetime.end(4, %a) <-- (1) %a.next = getelementptr i32* %a, 1 br %block Does (1) mean the end of lifetime for the 4 bytes that %a happens to be pointing to in the current iteration? My guess is "yes". Case 2: %a = i32* ... llvm.lifetime.begin(4, %a) ... llvm.lifetime.end(4, %a) <-- (2) %b = load i32 %ptr <-- (3) Is (2) a guarantee that *%ptr and *%a are not aliased? If (2) and (3) were in the opposite order, would it be illegal to move (3) past (2)? -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Seemingly Similar Threads
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?