This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes] Tail call libcalls where possible
AbandonedPublic

Authored by luke on Feb 1 2023, 9:48 AM.

Details

Summary

When making a libcall when legalizing the result of a node, check if the node is in tail call position. If it is, then generate a tail call instead.

The main issue encountered whilst working on this was that the type legalizer assumes that the root node isn't changed, and actually wrapped it in a handle.
Due to the fact that creating a tail call actually sets the root, I had to remove these bits.

Also since tail calls don't actually return any result node (just a tail call node with a chain), there's nothing for the type legalizer to work with when it analyzes all of the legalized node's uses.
But because tail call position means that the node was just used by bitcasts/register copies and return nodes (that are now dead), I've just opted to delete them here.

I could be going about this the completely wrong way, any suggestions on how to do this in a more sensible manner are very much welcome.

Diff Detail

Event Timeline

luke created this revision.Feb 1 2023, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 9:48 AM
luke requested review of this revision.Feb 1 2023, 9:48 AM
luke updated this revision to Diff 493993.Feb 1 2023, 9:51 AM

Update commit message, didn't realize that arc diff overwrote it

luke added inline comments.Feb 1 2023, 9:53 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
208

I removed the handle here because it prevents the root node from being delete-able (DeleteNode throws an assertion complaining that it's still in use by the handle)

llvm/test/CodeGen/RISCV/libcall-tail-calls.ll
237–244

This test fails because the checks generated by update_llc_checks.py seem overlap

luke added inline comments.
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
208

It didn't seem to affect any test cases but I'm not sure what I'm missing... I'd love to know if there's another way around this

luke abandoned this revision.Apr 3 2023, 4:35 AM