[llvm] [LLVM][Coroutines] Introduce TBAA metadata for coro frame object (PR #176543)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 21 00:58:08 PST 2026


yonillasky wrote:

> > If we look at this from a more theoretical standpoint, then using TBAA for this is not the correct approach. What we are attempting to do in this draft is tricking the AA to believe that the underlying types are not the same (even though they are). While these objects can never alias, it's not type based information that guarantees this.
> 
> This may not be accurate. From C++'s perspective, the type of the coroutine frame of every coroutine function is a half opaque type. We can interpret this as the type of every coroutine frame is unique.

There is a sleight of hand in here.
Imagine that a coroutine has captured an int x and an int *p

the coroutine has a loop where it loads x and p, then does some RMW on *p.
If we did normal C++ TBAA typing of the coroutine frame, it would consider the reload of x (type int) as potentially aliasing the RMW on *p (type is also int). AA itself also may have a hard time proving `p` and the slot of `x` (both int*) do not alias. so LICM will not be able to move the reload of `x` out of the loop, even though it never changes.

The fake "scalar" type in this PR makes it so we don't hit this problem, but even this hack isn't quite enough, because of the two TBAA roots problem.

https://github.com/llvm/llvm-project/pull/176543


More information about the llvm-commits mailing list