[all-commits] [llvm/llvm-project] 3bb396: [coro] Lower `llvm.coro.await.suspend.handle` to r...

Hans via All-commits all-commits at lists.llvm.org
Wed May 15 06:29:30 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3bb39690d729d85cd93c9dd6e750d82d6f367541
      https://github.com/llvm/llvm-project/commit/3bb39690d729d85cd93c9dd6e750d82d6f367541
  Author: Hans <hans at hanshq.net>
  Date:   2024-05-15 (Wed, 15 May 2024)

  Changed paths:
    M clang/lib/CodeGen/CGCoroutine.cpp
    M clang/test/CodeGenCoroutines/coro-await.cpp
    R clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
    M clang/test/CodeGenCoroutines/coro-symmetric-transfer-02.cpp
    M llvm/docs/Coroutines.rst
    M llvm/include/llvm/IR/Intrinsics.td
    M llvm/lib/Transforms/Coroutines/CoroInternal.h
    M llvm/lib/Transforms/Coroutines/CoroSplit.cpp
    M llvm/lib/Transforms/Coroutines/Coroutines.cpp
    M llvm/test/Transforms/Coroutines/coro-await-suspend-lower-invoke.ll
    M llvm/test/Transforms/Coroutines/coro-await-suspend-lower.ll
    R llvm/test/Transforms/Coroutines/coro-preserve-final.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail1.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail10.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail2.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail3.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail4.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail5.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail6.ll
    M llvm/test/Transforms/Coroutines/coro-split-musttail7.ll

  Log Message:
  -----------
  [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (#89751)

The C++ standard requires that symmetric transfer from one coroutine to
another is performed via a tail call. Failure to do so is a miscompile
and often breaks programs by quickly overflowing the stack.

Until now, the coro split pass tried to ensure this in the
`addMustTailToCoroResumes()` function by searching for
`llvm.coro.resume` calls to lower as tail calls if the conditions were
right: the right function arguments, attributes, calling convention
etc., and if a `ret void` was sure to be reached after traversal with
some ad-hoc constant folding following the call.

This was brittle, as the kind of implicit variants required for a tail
call to happen could easily be broken by other passes (e.g. if some
instruction got in between the `resume` and `ret`), see for example
9d1cb18d19862fc0627e4a56e1e491a498e84c71 and
284da049f5feb62b40f5abc41dda7895e3d81d72.

Also the logic seemed backwards: instead of searching for possible tail
call candidates and doing them if the circumstances are right, it seems
better to start with the intention of making the tail calls we need, and
forcing the circumstances to be right.

Now that we have the `llvm.coro.await.suspend.handle` intrinsic (since
f78688134026686288a8d310b493d9327753a022) which corresponds exactly to
symmetric transfer, change the lowering of that to also include the
`resume` part, always lowered as a tail call.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list