[PATCH] D24517: GVN-hoist: fix store past load dependence analysis (PR30216)

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 14 14:20:00 PDT 2016


On Tue, Sep 13, 2016 at 7:38 PM, Daniel Berlin via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Actually, you can build a walker already that will give you war dependence
> info.

The more I try, the more I think WAR dependences cannot be extracted
from the current MemorySSA walker: all liveOnEntry uses would not
be reached by walking through the MSSA.

>
> Here is the pseudo code for a getClobberingAccess (note that it is faster to
> build the entire aliased load set than to call this multiple times.  Noted
> below what to change to do that).  Note that it assumes transitivity in
> aliasing, but this is easy to fix by changing the outerworklist to also
> include store uses.
>
> Initialize OuterWorklist to be
> cachingWalker->getClobberingAccess(OriginalStore)
> while (!OuterWorklist.empty())
>   CurrentStore = OuterWorklist.pop_front();
>
>   // Any load that is aliased with the store must be a user of the store in
> use-optimized memoryssa
>   for each User of CurrentStore:

The users of CurrentStore are all downwards: these users are RAW
dependent on CurrentStore.

>     if (isa<MemoryUse>(User))
>       UseWorklist.push_back(User)
>
>   while (!UseWorklist.empty())
>     CurrentAccess = UseWorklist.pop_front();
>     if (StoreClobbersLoad(OriginalStore, CurrentAccess)) // This is
> instructionClobbersQuery, basically
>         return CurrentAccess // If you change this to insert it into a set
> instead of returning, you can get the entire set of dominating aliased loads
>
>   // Keep going up until we've gotten past the attempted hoist point
>   if (!MSSA->dominates(CurrentStore, HoistPoint))
>    OuterWorklist.push_back(cachingWalker->getClobberingAccess(CurrentStore->getDefiningAccess()))

The only way to reach uses above a store is by walking through the
def-def chain as in the above line, and then from there walking all the
uses, that may also be uses of OriginalStore.

This is exactly what is currently implemented in trunk: from OriginalStore
we go to ->getDefiningAccess() and from there we walk through all uses.
It does not work because when the def-def chain may point to a store that
does not clobber the OriginalStore, and then the reachable uses are not
clobering OriginalStore.

Another example in which there is no def-def chain and
it is illegal to move the store above the load:

load @A ; MemoryUse(LiveIn)
store @A ; 1 = MemoryDef(LiveIn)

liveOnEntry uses cannot be reached by walking through the MSSA.


More information about the llvm-commits mailing list