[PATCH] D101980: [RFC] [Coroutines] Put the contents of byval argument to the frame

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 13 19:04:15 PDT 2021


ChuanqiXu added a comment.

In D101980#2757573 <https://reviews.llvm.org/D101980#2757573>, @lxfind wrote:

> Here is an idea:
> we could introduce an intrinsics that doesn't do anything but just server the purpose of telling the compiler to not optimize out a pointer (i.e. indicating maywrite to the pointer).
> And in front end, for every copy we create from the parameter, we mark the local copy with that intrinsics. This will make sure that memcpyopt will never optimize it out.

It sounds like we still need to touch other passes other coroutine.

I spent some time to think about the solution we could do in the coroutine passes only. And I only get something really like workaround:

  If we found the uses of byval argument in the spills
       we could emit an extra alloca and a copy to replace the byval argument.

The insight is the byval argument shouldn't come up in the coroutine frame. There should be an alloca to replace all the uses of the byval argument in the coroutine. If there isn't one, it means that the alloca must be optimized by some passes, so we need to emit it again.
But this solution looks really like workaround which tries to solve bug 48857 <https://bugs.llvm.org/show_bug.cgi?id=48857>. And I found this solution can't solve the the problem in all environment. Like https://godbolt.org/z/K63KP8eaz. Here should be the implicit argument mentioned by @rjmccall. There are cases where arguments are passed by value semantically but passed by reference actually. Then if we decide to go to this direction, the only solution I found is to emit another attribute, although this attribute has the same semantic with `byval`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101980/new/

https://reviews.llvm.org/D101980



More information about the llvm-commits mailing list