This is an archive of the discontinued LLVM Phabricator instance.

[X86][NFC] structure-return simplificiation
ClosedPublic

Authored by urnathan on Sep 17 2021, 8:01 AM.

Details

Summary
The X86 backend only needs to know whether structure return is via an
sret pointer.  This removes the categorization enumeration and adjusts
and renames the related functions.

Diff Detail

Event Timeline

urnathan created this revision.Sep 17 2021, 8:01 AM
urnathan requested review of this revision.Sep 17 2021, 8:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2021, 8:01 AM
rnk added a comment.Sep 17 2021, 10:25 AM

All three conditions that use this value are trying to determine if the callee is expected to pop the sret pointer off the stack. They have some duplicate subtarget checks that can probably be simplified. They all check these conditions:

  • !IsMCU: MCU doesn't seem to pop the sret value ever
  • !Is64Bit: In the TCO eligbility check, this is expressed as Is32bit, but is functionally identical
  • !IsMSVC: MSVC doesn't do this callee-pop sret thing
  • !IsInReg: sret parameters marked with inreg are not popped (reasonable)

So, can I suggest this simplification:

  • replace the IsMCU parameter with the subtarget
  • move all three subtarget checks into these functions. Consider sharing them, maybe a helper like isSRetCalleePop, it's basically Is32bit && !IsMSVC && !IsMCU.
  • make the helper names more precise: returnHasCalleePopSRet / argsHaveCalleePopSRet
llvm/lib/Target/X86/X86ISelLowering.cpp
3352–3353

There's a subtlety here: LLVM doesn't require that sret arguments come first. However, it would be impossible for the callee to pop off the second argument and leave behind the first, so this convention is only ever used when the sret argument appears first. Therefore only the first argument needs to be checked.

4665–4668

This comment should live with the target checks if those get moved.

urnathan updated this revision to Diff 377244.Oct 5 2021, 7:58 AM

thanks for your comments. Moving the check-which-ABI bits into the predicate does make things much simpler. I chose to templatize it, rather than write the same thing twice. That does mean taking a SmallVector<T> reference, rather than ArrayRef, because template deduction. But that ends up with less work to do anyway. I reordered the checks to get the best short-circuiting (heuristic guesswork though).

would you prefer anonymous namespace, or stick with the static fn?

rnk accepted this revision.Oct 5 2021, 10:58 AM

lgtm, thanks!

would you prefer anonymous namespace, or stick with the static fn?

LLVM has a guideline preferring static:
https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

This revision is now accepted and ready to land.Oct 5 2021, 10:58 AM
This revision was automatically updated to reflect the committed changes.