This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Implement isUsedByReturnOnly TargetLowering hook in order to tailcall more libcalls
ClosedPublic

Authored by asb on Aug 3 2022, 11:33 AM.

Details

Summary

Prior to this patch, libcalls inserted by the SelectionDAG legalizer
could never be tailcalled. The eligibility of libcalls for tail calling
is is partly determined by checking TargetLowering::isInTailCallPosition
and comparing the return type of the libcall and the calleer.
isInTailCallPosition in turn calls TargetLowering::isUsedByReturnOnly
(which always returns false if not implemented by the target).

This patch provides a minimal implementation of
TargetLowering::isUsedByReturnOnly - enough to support tail calling
libcalls on hard float ABIs. Soft-float ABIs are left for a follow on
patch. libcall-tail-calls.ll also shows missed opportunities to tail
call integer libcalls, but this is due to issues outside of
the isUsedByReturnOnly hook.

The isUsedByReturnOnly hook is essentially the same as for X86/Arm/AArch64. I've tried to clean it up a bit, but please do check I haven't copied across any bad practices / outdated API usage.

Diff Detail

Event Timeline

asb created this revision.Aug 3 2022, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 11:33 AM
asb requested review of this revision.Aug 3 2022, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 11:33 AM
reames accepted this revision.Aug 9 2022, 8:27 AM

LGTM w/minor comment

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
11791

It doesn't look like this variable is ever used. Delete it, and just assign Chain directly on return.

This revision is now accepted and ready to land.Aug 9 2022, 8:27 AM