[MemorySSA] Make the visitor more careful with calls.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Wed, 30 Mar 2016 03:12:08 +0000 (03:12 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Wed, 30 Mar 2016 03:12:08 +0000 (03:12 +0000)
commit49cad7d70b663a1f258c40cbc94deb01cd4ba5df
tree7d0ae225a1f8b812db8e2a8d9ff9948173a5b7be
parent81c3ddeb1c24671c03a25420745ca38efba42263
[MemorySSA] Make the visitor more careful with calls.

Prior to this patch, the MemorySSA caching visitor would cache all
calls that it visited. When paired with phi optimization, this can be
problematic. Consider:

define void @foo() {
  ; 1 = MemoryDef(liveOnEntry)
  call void @clobberFunction()
  br i1 undef, label %if.end, label %if.then

if.then:
  ; MemoryUse(??)
  call void @readOnlyFunction()
  ; 2 = MemoryDef(1)
  call void @clobberFunction()
  br label %if.end

if.end:
  ; 3 = MemoryPhi(...)
  ; MemoryUse(?)
  call void @readOnlyFunction()
  ret void
}

When optimizing MemoryUse(?), we visit defs 1 and 2, so we note to
cache them later. We ultimately end up not being able to optimize
passed the Phi, so we set MemoryUse(?) to point to the Phi. We then
cache the clobbering call for def 1 to be the Phi.

This commit changes this behavior so that we wipe out any calls
added to VisistedCalls while visiting the defs of a phi we couldn't
optimize.

Aside: With this patch, we now can bootstrap clang/LLVM without a
single MemorySSA verifier failure. Woohoo. :)

llvm-svn: 264820
llvm/lib/Transforms/Utils/MemorySSA.cpp
llvm/test/Transforms/Util/MemorySSA/function-clobber.ll