[PATCH] D105807: [X86] pr51000 struct return tailcalling

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 13 07:01:49 PDT 2021


urnathan added inline comments.


================
Comment at: llvm/test/CodeGen/X86/sibcall.ll:854
   %b = call fastcc %struct.foo* @ret_struct()
   tail call fastcc void @t21_f_sret2(%struct.foo* noalias sret(%struct.foo) %a, %struct.foo* noalias %b) nounwind
   ret void
----------------
efriedma wrote:
> Oh, now I remember what happened the last time someone tried to fix this... t21_sret_to_sret_structs_mismatch() is also illegal to transform, for similar reasons to t21_sret_to_non_sret().
Ah, I think I understand now -- I was thinking this would be UB, but I can see how it might be legit.  Let me walk though my understanding.
 
`define fastcc void @t21_sret_to_sret_structs_mismatch(%struct.foo* noalias sret(%struct.foo) %agg.result, %struct.foo* noalias %a) nounwind  {`
 we receive an sret as %agg.result and a explicit pointer in %a (to uninitialized memory? or is that too C++-specific?). 

` %b = call fastcc %struct.foo* @ret_struct()`
this gives us a pointer to a foo in %b [aside, this seems superfluous to the xform being tested?]

`  tail call fastcc void @t21_f_sret2(%struct.foo* noalias sret(%struct.foo) %a, %struct.foo* noalias %b) nounwind`
We call t21_f_sret2 passing it %a as its incoming sret pointer and %b as an explicit arg.  It'll return %a, not our incoming sret.  

I thought this would be UB, because we're not initializing our own return value -- in C++ we should be calling a constructor.  but (a) we could have inlined that and (b) it could be trivial and do nothing.  That was my logical error.

So, I think 
a) if we're not an sret function we can tail call[*],
b) else if we're calling a non-sret function we cannot tail call,
c) else if we're passing our sret register as the callee's sret register we can tail call[*],
d) else we cannot.
[*] provided the remaining checks are ok


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105807/new/

https://reviews.llvm.org/D105807



More information about the llvm-commits mailing list