This is an archive of the discontinued LLVM Phabricator instance.

[Coroutines] Don't use lifetime marker to decide whether an alloca should be put on the frame
AbandonedPublic

Authored by lxfind on Feb 10 2021, 11:05 AM.

Details

Summary

In the current logic, we look at the lifetime.start marker of each alloca, and check all uses of the alloca, to see if any pair of the lifetime marker and an use of alloca crosses suspension point.
This approach is unfortunately incorrect. An use of alloca does not need to be a direct use, but can be an indirect use through alias.
Only checking direct uses can miss cases where indirect uses are crossing suspension point.
This can be demonstrated in the newly added test case.
In the test case, both x and y are only directly used prior to suspend, but they are captured into an alias, merged through a PHINode (so they couldn't be materialized), and used after CoroSuspend.
If we only check whether the lifetime starts cross suspension points with direct uses, we will put the allocas to the stack, and then capture their addresses in the frame.

I also noticed that when we are sinking lifetime start markers, we didn't clean up the bitcasts that are no longer needed. This patch cleans that up too (to avoid having regressions due to this patch).
Since we no longer look at lifetime markers, we also need to be more conservative, and hence one test has to be updated to have nocapure to prove it's not escaped.

Diff Detail

Event Timeline

lxfind created this revision.Feb 10 2021, 11:05 AM
lxfind requested review of this revision.Feb 10 2021, 11:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2021, 11:05 AM
lxfind updated this revision to Diff 322763.Feb 10 2021, 11:08 AM

Update test

lxfind edited the summary of this revision. (Show Details)Feb 10 2021, 11:47 AM

Note: I believe it's still possible to take advantage of lifetime intrinsics, but the approach will be very different and I would prefer to implement that in a separate patch.

lxfind abandoned this revision.Feb 17 2021, 5:35 PM