This is an archive of the discontinued LLVM Phabricator instance.

[NFC] X86: Annotate sibcall test
AbandonedPublic

Authored by urnathan on Jul 14 2021, 10:11 AM.

Details

Summary

This annotates the current X86/sibcall.ll testcase about why a particular test can be tailcalled or not tailcalled. I've added QOI markers to ones that could be tailcalled, if we were sufficiently smart (eg as pr51000 points out). I also reordered the lit check lines so they are no longer between the function header and the body -- that makes it much easier to follow the llvm ir.

I figured this would be a good start before progressing with D105807 (thanks for the feedback on that)

Diff Detail

Event Timeline

urnathan created this revision.Jul 14 2021, 10:11 AM
urnathan requested review of this revision.Jul 14 2021, 10:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 10:11 AM

I'd prefer to structure the comments in the following form, so it's clear at a glance which transforms are legal/illegal:

; Tailcall legal: caller and callee signatures match
; QOI: we don't currently emit a tailcall on i686 because arguments on stack don't match.
llvm/test/CodeGen/X86/sibcall.ll
68

The callee owns the argument space; we can rewrite it if we need to. We do in fact rewrite it if you use musttail. (Well, the IR verifier doesn't allow musttail for this specific testcase, but in general.)

Yes, making sure we perform the operations in the right order can get a bit hairy, particularly in cases involving byval.

urnathan updated this revision to Diff 358742.Jul 14 2021, 2:01 PM

Thanks, like this?

urnathan marked an inline comment as done.Jul 14 2021, 2:02 PM
xbolva00 added inline comments.
llvm/test/CodeGen/X86/sibcall.ll
9

Looks like it was not regenerated by update_llc_test_checks.py.

mizvekov added inline comments.Jul 14 2021, 2:45 PM
llvm/test/CodeGen/X86/sibcall.ll
252

I think this one has to do with this: https://github.com/llvm/llvm-project/blob/3bf101f34cd466f103af00c764dc1cddb6eb14a6/llvm/lib/CodeGen/Analysis.cpp#L506

The block must end in a return statement or unreachable.

FIXME: Decline tailcall if it's not guaranteed and if the block ends in
an unreachable, for now. The way tailcall optimization is currently
implemented means it will add an epilogue followed by a jump. That is
not profitable. Also, if the callee is a special function (e.g.
longjmp on x86), it can end up causing miscompilation that has not
been fully understood.

The tail call is not done just because it is not a musttail and the code generated might have worse runtime cost.

So when we say we have a QOI issue, there are two issues conflated here:

  • Do we know how to do it profitably purely from a instruction cost perspective?
  • Can we figure out the sequence of instructions we actually need to tail call this at all?
urnathan updated this revision to Diff 358765.Jul 14 2021, 2:58 PM
urnathan added inline comments.
llvm/test/CodeGen/X86/sibcall.ll
9

That seems to be breaking the llvm ir apart around the lit patterns, making them hard to read. What is the rationale for doing that?

252

QOI is always a judgement call. What are you suggesting for this patch?

mizvekov added inline comments.Jul 14 2021, 3:08 PM
llvm/test/CodeGen/X86/sibcall.ll
252

If we are digging down into the reasons why the sibcall is not performed, even if we do not fully understand why, my suggestion would be to mention if there is a difference in the behavior between musttail or not.

Unless there is other test cases in the suite which already go over this.

xbolva00 added inline comments.Jul 14 2021, 3:40 PM
llvm/test/CodeGen/X86/sibcall.ll
9

Well.. it is a common standard in the LLVM project to make test updates easier for future development.

“Hard to read” is subjective, LLVM devs are familiar with this style of tests.

urnathan abandoned this revision.Jul 16 2021, 7:59 AM