This is an archive of the discontinued LLVM Phabricator instance.

[Coroutine] Collect CoroBegin if all of terminators are dominated by one coro.destroy
ClosedPublic

Authored by ChuanqiXu on Apr 15 2021, 7:58 PM.

Details

Summary

The original logic seems to be we could collecting a CoroBegin if one of the terminators could be dominated by one of coro.destroy, which doesn't make sense.
This patch rewrites the logics to collect CoroBegin if all of terminators are dominated by one coro.destroy. If there is no such coro.destroy, we would call hasEscapePath to evaluate if we should collect it.

Test Plan: check-llvm

Diff Detail

Event Timeline

ChuanqiXu created this revision.Apr 15 2021, 7:58 PM
ChuanqiXu requested review of this revision.Apr 15 2021, 7:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2021, 7:58 PM

Does it require that all terminators to be dominated by the same coro.destroy?
Reading the comments in the original code, I think the condition is that for each terminator it's dominated by a coro.destroy, but it doesn't require all terminators to be dominated by the same coro.destroy.
The original code does seem to be buggy, but the fix may not be correct. Perhaps in the next statement, the check on hasEscapePath and ReferencedCoroBegins.count is problematic?

Does it require that all terminators to be dominated by the same coro.destroy?
Reading the comments in the original code, I think the condition is that for each terminator it's dominated by a coro.destroy, but it doesn't require all terminators to be dominated by the same coro.destroy.
The original code does seem to be buggy, but the fix may not be correct. Perhaps in the next statement, the check on hasEscapePath and ReferencedCoroBegins.count is problematic?

The codes I changed means if all terminators are dominated by one coro.destroy we can collect the corresponding coro.begin directly. Then if there is no coro.destroy to dominate all terminators, we could only search in hasEscapePath. The key idea here is hasEscapePath is relatively slow, so we want to avoid to call it as much as possible. The check on ReferencedCoroBegins.count and hasEscapePath just did this.

In another words, we could use hasEscapePath to handle all the cases if we don't care about compile-time.

lxfind accepted this revision.Apr 20 2021, 5:20 PM

I see. LGTM. Thanks for fixing. Could you also add comments to the llvm::all_of search with what you just described?

This revision is now accepted and ready to land.Apr 20 2021, 5:20 PM
ychen added a subscriber: ychen.Apr 20 2021, 5:53 PM
ychen added inline comments.
llvm/test/Transforms/Coroutines/coro-elide.ll
97

Missing a CHECK?

ChuanqiXu updated this revision to Diff 339075.Apr 20 2021, 7:18 PM

Address the comments.

ChuanqiXu added inline comments.Apr 20 2021, 7:19 PM
llvm/test/Transforms/Coroutines/coro-elide.ll
97

Thanks for reminding. It is legacy comments before previously. Here I use print(i32 2) to judge this coroutine is elided.