[SROA] Make the computation of adjusted pointers not leak GEP
authorChandler Carruth <chandlerc@gmail.com>
Fri, 2 Jan 2015 02:47:38 +0000 (02:47 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 2 Jan 2015 02:47:38 +0000 (02:47 +0000)
commit5986b541d4e575b06b48c89169925b57c80b8d04
tree4f98b70d25ba6f9aefd1aa2b56915452a76c1f53
parent017822d81a37f2ca4cd7adade0fc7268522c2c8f
[SROA] Make the computation of adjusted pointers not leak GEP
instructions.

I noticed this when working on dialing up how aggressively we can
pre-split loads and stores. My test case wasn't passing because dead
GEPs into the allocas persisted when they were built by this routine.
This isn't terribly harmful, we still rewrote and promoted the alloca
and I can't conceive of how to cause this to happen in a case where we
will keep the exact same alloca but rewrite and promote the uses of it.
If that ever happened, we'd get an assert out of mem2reg.

So I don't have a direct test case yet, but the subsequent commit's test
case wouldn't pass without this. There are other problems fixed by this
patch that I spotted purely by inspection such as the fact that
getAdjustedPtr could have actually deleted dead base pointers. I don't
know how to get a base pointer to go into getAdjustedPtr today, so
I think this bug could never have manifested (and I certainly can't
write a test case for it) but, it wasn't the intent of the code. The
code really just wanted to GC the new instructions built. That can be
done more directly by comparing with the base pointer which is the only
non-new instruction that this code can return.

llvm-svn: 225073
llvm/lib/Transforms/Scalar/SROA.cpp