This is an archive of the discontinued LLVM Phabricator instance.

SimplifyCFG: Avoid miscompilations due to removed lifetime intrinsics
ClosedPublic

Authored by dotdash on Jul 28 2014, 1:51 PM.

Details

Summary

For example in a loop, just removing a lifetime.end intrinsic can
interact badly with loop rotation, which might move the corresponding
lifetime.start intrinsic to the end of the loop.

So with the lifetime.end intrinsic removed you can end up with something
like:

block:
    store i8 %foo, i8* %bar
    call void @llvm.lifetime.start(i64 1, i8* %bar)

Without a corresponding lifetime.end, meaning that the store is invalid.
If the lifetime.end intrinsic is kept, we get this instead:

block:
    store i8 %foo, i8* %bar
    call void @llvm.lifetime.end(i64 1, i8* %bar)
    call void @llvm.lifetime.start(i64 1, i8* %bar)

Which is fine, since the store is within a valid lifetime region.

Diff Detail

Event Timeline

dotdash updated this revision to Diff 11955.Jul 28 2014, 1:51 PM
dotdash retitled this revision from to SimplifyCFG: Avoid miscompilations due to removed lifetime intrinsics.
dotdash updated this object.
dotdash edited the test plan for this revision. (Show Details)
dotdash added reviewers: rnk, rafael.
dotdash added a subscriber: Unknown Object (MLST).
rnk edited edge metadata.Jul 28 2014, 2:20 PM

I guess this is OK for now. We really need to revisit the design of lifetime.end and start. We might want to invent something much more limited to describe the scope of stack objects, instead of having this general thing intended to describe heap allocations as well.

rafael accepted this revision.Jul 29 2014, 11:46 AM
rafael edited edge metadata.

This is fine by me.

I agree with Reid that we need to figure out what to do with the lifetime intrinsics, but lets not miscompile code while we do that.

This revision is now accepted and ready to land.Jul 29 2014, 11:46 AM

I should note that I do not have commit access and need somebody to commit this for me.

Thanks!