[EarlyCSE] Exploit open ended invariant.start scopes
authorPhilip Reames <listmail@philipreames.com>
Wed, 14 Mar 2018 21:35:06 +0000 (21:35 +0000)
committerPhilip Reames <listmail@philipreames.com>
Wed, 14 Mar 2018 21:35:06 +0000 (21:35 +0000)
commit0adbb1940997e1f9ac1ee5340fafe9b156e96a2d
tree40afd86a78640c62524cc411906857d670c38570
parentc7fd1540b3009e576060b3ed01e59370efd8da0a
[EarlyCSE] Exploit open ended invariant.start scopes

If we have an invariant.start with no corresponding invariant.end, then the memory location becomes invariant indefinitely after the invariant.start. As a result, anything dominated by the start is guaranteed to see the value the memory location had when the invariant.start executed.

This patch adds an AvailableInvariants table which tracks the generation a particular memory location became invariant and then uses that information to allow value forwarding that would otherwise be disallowed by potentially aliasing stores. (Reminder: In EarlyCSE everything clobbers everything by default.)

This should be compatible with the MemorySSA variant, but design is generational. We can and should add first class support for invariant.start within MemorySSA at a later time.  I took a quick look at doing so, but probably need some input from a MemorySSA expert.

Differential Revision: https://reviews.llvm.org/D43716

llvm-svn: 327577
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/test/Transforms/EarlyCSE/invariant-loads.ll
llvm/test/Transforms/EarlyCSE/invariant.start.ll