[X86] Don't setup and teardown memory for a musttail call
authorReid Kleckner <rnk@google.com>
Mon, 2 Dec 2019 21:15:30 +0000 (13:15 -0800)
committerReid Kleckner <rnk@google.com>
Fri, 6 Dec 2019 20:58:54 +0000 (12:58 -0800)
commitc089f0289856b8f72b06c30daa7848e431c8e36e
treee92c1fde3bd3af18b16917e16d32ce4c0c55b739
parenta7bdab2e9d59ba0fdf06390f4ddadfd00fe50f2e
[X86] Don't setup and teardown memory for a musttail call

Summary:
musttail calls should not require allocating extra stack for arguments.
Updates to arguments passed in memory should happen in place before the
epilogue.

This bug was mostly a missed optimization, unless inalloca was used and
store to push conversion fired.

If a reserved call frame was used for an inalloca musttail call, the
call setup and teardown instructions would be deleted, and SP
adjustments would be inserted in the prologue and epilogue. You can see
these are removed from several test cases in this change.

In the case where the stack frame was not reserved, i.e. call frame
optimization fires and turns argument stores into pushes, then the
imbalanced call frame setup instructions created for inalloca calls
become a problem. They remain in the instruction stream, resulting in a
call setup that allocates zero bytes (expected for inalloca), and a call
teardown that deallocates the inalloca pack. This deallocation was
unbalanced, leading to subsequent crashes.

Reviewers: hans

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71097
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/cfguard-checks.ll
llvm/test/CodeGen/X86/musttail-inalloca.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/musttail-tailcc.ll
llvm/test/CodeGen/X86/musttail-varargs.ll