[PATCH] D46262: Enable sibling-call optimization for functions returning structs

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 12:22:24 PDT 2019


efriedma added a comment.

The testcase I actually wanted, which incorrectly forms a tail call:

  define fastcc void @t21_sret_to_sret_arg_mismatch(%struct.foo* noalias sret %agg.result, %struct.foo* noalias %a) nounwind  {
    %b = call fastcc %struct.foo* @ret_struct()
    tail call fastcc void @t21_f_sret(%struct.foo* noalias sret %a, %struct.foo* noalias %b) nounwind
    ret void
  }
  declare ccc %struct.foo* @ret_struct() nounwind
  declare fastcc void @t21_f_sret(%struct.foo* noalias sret, %struct.foo* noalias) nounwind
  %struct.foo = type { [4 x i32] }

Apparently other, more obvious constructs don't actually trigger the issue; there was a check introduced in https://reviews.llvm.org/D8510 which suppresses tail calls in some, but not all, of the relevant cases.



================
Comment at: lib/Target/X86/X86ISelLowering.cpp:4298
+  // Struct-return functions need to return its argument in RAX, so they can not
+  // sibcall non-struct-return functions.
+  if (isCalleeStructRet != isCallerStructRet ||
----------------
Not sure why the `CallerF.arg_size() != Outs.size()` check is necessary?  In any case, needs a comment to explain.


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

https://reviews.llvm.org/D46262





More information about the llvm-commits mailing list