[LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
Nick Lewycky
nicholas at mxc.ca
Wed Dec 26 15:08:40 PST 2012
On 12/26/2012 02:37 PM, Krzysztof Parzyszek wrote:
> 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".
Yes. It ends the lifetime of the memory that %a happens to be pointing
to, dynamically, at the moment that instruction is executed.
> 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?
Nope. Also, (2)+(3) together don't imply that %ptr and %a are NoAlias
since loading after lifetime ends gives you undef, not undefined behaviour.
> If (2) and (3) were in the opposite order, would it be illegal to move
> (3) past (2)?
Not necessarily. If you can show that they're NoAlias, you're free to
reorder them. If though some stroke of crazy, you can show that the
program has the same behaviour when %b is replaced with undef, then
you're free to move them. Otherwise, yes, it would be illegal to move
(3) before (2).
Nick
More information about the llvm-dev
mailing list