[PATCH] D89711: [Coroutine] Prevent value reusing across coroutine suspensions in EarlyCSE and GVN

Xun Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 10:02:26 PDT 2020


lxfind created this revision.
lxfind added reviewers: wenlei, efriedma, nikic, fhahn.
Herald added subscribers: llvm-commits, modimo, jfb, modocache, hiraditya.
Herald added a project: LLVM.
lxfind requested review of this revision.

There are two problems with reusing values across coroutine suspensions:

1. It has been assumed that all the code within the same function would run in the same thread. For example, the glibc library pthread_self is defined with __attribute__((__const__)) (which would have readnone attribute in LLVM IR) even though it in fact reads global memory. This was OK because within the same function the thread ID will never change in a non-coroutine function. Optimizazers take advantage of that and would reuse the results if there are multiple calls to pthread_self within the same function. However with coroutines this is no longer true. We cannot reuse the results of pthread_self if they cross suspension points because they could be running on different threads.
2. Any data that needs to lives across coroutine suspensions will have to be spilled onto the coroutine frame (heap). Value reusing across suspensions would generate lots of data that needs to live on the frame. This can be expensive and makes the frame large unnecessarily in common cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89711

Files:
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/Coroutines/coro-no-value-reuse-across-suspend.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89711.299084.patch
Type: text/x-patch
Size: 17632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201019/62bc61df/attachment.bin>


More information about the llvm-commits mailing list