[GlobalOpt] Remove preallocated calls when possible
authorArthur Eubanks <aeubanks@google.com>
Mon, 1 Jun 2020 20:32:15 +0000 (13:32 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 18 Jun 2020 16:56:13 +0000 (09:56 -0700)
commit91ef9305268760727e8cc90e2542a803621b2336
tree61074296db38603c3c4d868ab609b5d87da48489
parent3e59dfc301240ffb5e82bc43e05225d0d51d5cfa
[GlobalOpt] Remove preallocated calls when possible

When possible (e.g. internal linkage), strip preallocated attribute off
parameters/arguments.
This requires removing the "preallocated" operand bundle from the call
site, replacing @llvm.call.preallocated.arg() with an alloca and a
bitcast to i8*, and removing the @llvm.call.preallocated.setup(). Since
@llvm.call.preallocated.arg() can be called multiple times with the same
arg index, we create an alloca per arg index.
We add a @llvm.stacksave() where the @llvm.call.preallocated.setup() was
and a @llvm.stackrestore() after the preallocated call to prevent the
stack from blowing up. This is valid because the argument would normally
not exist on the stack after the call before the transformation.

This does not currently handle all possible preallocated calls. We will
need to figure out where to put @llvm.stackrestore() in the cases where
there is no obvious place to put it, for example conditional
preallocated calls, invokes.

This sort of transformation may need to be moved to somewhere more
accessible to accomodate similar transformations (like inlining) in the
future.

Reviewers: efriedma, hans

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80951
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/fastcc.ll
llvm/test/Transforms/GlobalOpt/preallocated.ll [new file with mode: 0644]