Created attachment 5960 [details] .ll testcase (run opt -basicaa -gvn) This is a breakout bug from bug 8886 comment 2. The problem is that we have in pseudo: %x = alloca store @CONSTANT, %x call @external1() %DEAD = load %x call @external2(%x) and the load isn't being eliminated by GVN. MemDep does its backwards scan but when it asks BasicAA about the call to external1, BasicAA looks at the alloca's address leaking into external2 and bails returning ModRef.
One way to fix this is to generalize llvm::PointerMayBeCaptured which already takes bool ReturnCaptures and bool StoreCaptures to take a generic "ignore this capture" functor. MemDep could then provide such a functor that ignores captures that happen too late using a DominatorTree for intra-block analysis. The query would have to go through alias analysis and things like the getModRefInfo implementation in BasicAA would use it. This will require expanding the AA interface a little. I'm not sure how folks feel about using a functor. One alternative is to return the list of all capturing instructions, though that list could get needlessly big on large functions where most instructions capture.
Fixed in r144580.