This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][Coroutines] Add tail-call check with context information for coroutines
ClosedPublic

Authored by tingwang on Aug 16 2022, 3:38 AM.

Details

Summary

This is an attempt to solve https://github.com/llvm/llvm-project/issues/56679 by rejecting musttail in CoroSplitPass on ppc conditionally based on CallInst and target configuration.

TailCallOptimization is conditionally eligible on PPC as details explained in PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4(). The check happens during instruction selection.

Coroutines need to know the eligibility during transformation. From the CallInst provided, ppc can decide if indirect call can be turned into tail call.

Diff Detail

Event Timeline

tingwang created this revision.Aug 16 2022, 3:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2022, 3:38 AM
tingwang requested review of this revision.Aug 16 2022, 3:38 AM

Test case clang/test/CodeGenCoroutines/pr56329.cpp with this patch will not generate musttail on ppc.

Test case clang/test/CodeGenCoroutines/pr56329.cpp with this patch will not generate musttail on ppc.

So will pr56329.cpp fail after this patch? I guess we need REQUIRE/XFAIL clause to pr56329.cpp for pcc.

llvm/include/llvm/Analysis/TargetTransformInfo.h
769
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
1378–1379
tingwang updated this revision to Diff 453188.Aug 16 2022, 8:10 PM

Update according to comments.

Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2022, 8:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tingwang marked 2 inline comments as done.Aug 16 2022, 8:10 PM
ChuanqiXu accepted this revision.Aug 16 2022, 8:14 PM

LGTM with comment addressed. Thanks!

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
346

The default implementation should return supportsTailCalls().

This revision is now accepted and ready to land.Aug 16 2022, 8:14 PM
tingwang updated this revision to Diff 453193.Aug 16 2022, 9:13 PM

For default implementation of supportsTailCallFor, return supportsTailCalls() as suggested in comments.

tingwang marked an inline comment as done.Aug 16 2022, 9:15 PM

LGTM with comment addressed. Thanks!

Thank you! I'm looking forward to comments from ppc.

shchenz accepted this revision as: shchenz.Aug 18 2022, 8:15 PM

This LGTM. Although supportsTailCallFor is not completely equal to how PPC backend checks tail call support, we can continuously improve this when we have more caller of supportsTailCallFor() in future.