Fix PR8735, a really terrible problem in the inliner's "alloca merging"
authorChris Lattner <sabre@nondot.org>
Mon, 6 Dec 2010 07:52:42 +0000 (07:52 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 6 Dec 2010 07:52:42 +0000 (07:52 +0000)
commit6c3ee0f3c9684e588c8852d90c891d6354175c9e
tree5375e2e92f266beea8292c29d93e97301190bf87
parent39add23dc54a1580983b1901384688d6622daa3b
Fix PR8735, a really terrible problem in the inliner's "alloca merging"
optimization.

Consider:
static void foo() {
  A = alloca
  ...
}

static void bar() {
  B = alloca
  ...
  call foo();
}

void main() {
  bar()
}

The inliner proceeds bottom up, but lets pretend it decides not to inline foo
into bar.  When it gets to main, it inlines bar into main(), and says "hey, I
just inlined an alloca "B" into main, lets remember that.  Then it keeps going
and finds that it now contains a call to foo.  It decides to inline foo into
main, and says "hey, foo has an alloca A, and I have an alloca B from another
inlined call site, lets reuse it".  The problem with this of course, is that
the lifetime of A and B are nested, not disjoint.

Unfortunately I can't create a reasonable testcase for this: the one in the
PR is both huge and extremely sensitive, because you minor tweaks end up
causing foo to get inlined into bar too early.  We already have tests for the
basic alloca merging optimization and this does not break them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120995 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/IPO/Inliner.cpp