This is an archive of the discontinued LLVM Phabricator instance.

[X86] Don't setup and teardown memory for a musttail call
ClosedPublic

Authored by rnk on Dec 5 2019, 4:09 PM.

Details

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.

Event Timeline

rnk created this revision.Dec 5 2019, 4:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2019, 4:09 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
hans accepted this revision.Dec 6 2019, 1:47 AM

lgtm

This revision is now accepted and ready to land.Dec 6 2019, 1:47 AM
This revision was automatically updated to reflect the committed changes.