Skip to content

Conversation

@mincrmatt12
Copy link
Contributor

The ARM target doesn't support tail calls on certain older subarchitectures, however this information is not communicated to the target transform information. This causes coroutine symmetric transfer to fail as it adds musttail attributes which throw an assert during code generation. Exposing the underlying subtarget's supportsTailCall method to transforms (specifically the coroutine ones) allows coroutines to compile without crashing on these older subarchitectures (like ARMv6 on a Cortex-M0+)

See also 0b5ead6 and d2d77e0.

@llvmbot
Copy link
Member

llvmbot commented Oct 1, 2023

@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-coroutines

@llvm/pr-subscribers-backend-arm

Changes

The ARM target doesn't support tail calls on certain older subarchitectures, however this information is not communicated to the target transform information. This causes coroutine symmetric transfer to fail as it adds musttail attributes which throw an assert during code generation. Exposing the underlying subtarget's supportsTailCall method to transforms (specifically the coroutine ones) allows coroutines to compile without crashing on these older subarchitectures (like ARMv6 on a Cortex-M0+)

See also 0b5ead6 and d2d77e0.


Full diff: https://github.com/llvm/llvm-project/pull/67932.diff

1 Files Affected:

  • (modified) llvm/lib/Target/ARM/ARMTargetTransformInfo.h (+8)
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h index bb4b321b5300916..95cd1442e689299 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h @@ -333,6 +333,14 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> { bool hasArmWideBranch(bool Thumb) const; + bool supportsTailCalls() const { + return ST->supportsTailCall(); + } + + bool supportsTailCallFor(const CallBase *CB) const { + return supportsTailCalls(); + } + /// @} }; 
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@mincrmatt12 mincrmatt12 force-pushed the supports-tail-calls-tti branch from 13b1d74 to b2bced0 Compare October 1, 2023 19:53
@davemgreen
Copy link
Collaborator

This sounds OK. Do you have a testcase for the change in coroutine behaviour?

The ARM target doesn't support tail calls on certain older architectures, however this information is not communicated to the target transform information. This causes coroutine symmetric transfer to fail as it adds musttail attributes which throw an assert during code generation.
@mincrmatt12 mincrmatt12 force-pushed the supports-tail-calls-tti branch from b2bced0 to 53783c9 Compare March 9, 2024 22:59
@mincrmatt12
Copy link
Contributor Author

Sorry about the large delay -- I've just added a test (that's almost identical to the existing one for similar behaviour on ppc64) to verify the musttail calls are not emitted on ARMv6 thumb.

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The supportsTailCallFor could be more precise but that is likely not a v6m issue. What you have LGTM in that regard.

@@ -0,0 +1,60 @@
; Test that ARMv6 correctly masks coroutine infrastructure from generating musttail calls
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S \
; RUN: -mtriple=arm-none-eabi -mcpu=cortex-m0 | FileCheck %s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth having an extra check line for an arch that does support tail calls, to show the difference between the two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants