[PATCH] D96922: [Coroutine] Check indirect uses of alloca when checking lifetime info

Xun Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 17 17:34:08 PST 2021


lxfind created this revision.
lxfind added reviewers: junparser, ChuanqiXu, rjmccall.
Herald added subscribers: hoy, modimo, wenlei, hiraditya.
lxfind requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In the existing 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 007.
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.

Instead of fixing it in D96441 <https://reviews.llvm.org/D96441> and D96566 <https://reviews.llvm.org/D96566>, this patch takes a different approach which I think is better.
We still checks the lifetime info in the same way as before, but with two differences:

1. The collection of liftime.start is moved into AllocaUseVisitor to make the logic more concentrated.
2. When looking at lifetime.start and use pairs, we not only checks the direct uses as before, but in this patch we check all uses collected by AllocaUseVisitor, which would include all indirect uses through alias. This will make the analysis more accurate without throwing away the lifetime optimization.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96922

Files:
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/test/Transforms/Coroutines/coro-alloca-07.ll
  llvm/test/Transforms/Coroutines/coro-alloca-08.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96922.324476.patch
Type: text/x-patch
Size: 13069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210218/9f90954a/attachment.bin>


More information about the llvm-commits mailing list