This is an archive of the discontinued LLVM Phabricator instance.

GVN-hoist: fix store past load dependence analysis (PR30216, PR30499)
ClosedPublic

Authored by sebpop on Oct 11 2016, 8:30 AM.

Details

Summary

This is a refreshed version of a patch that was reverted: it fixes
the problems reported in both PR30216 and PR30499, and
contains all the test-cases from both bugs.

To hoist stores past loads, we used to search for potential
conflicting loads on the hoisting path by following a MemorySSA
def-def link from the store to be hoisted to the previous
defining memory access, and from there we followed the def-use
chains to all the uses that occur on the hoisting path. The
problem is that the def-def link may point to a store that does
not alias with the store to be hoisted, and so the loads that are
walked may not alias with the store to be hoisted, and even as in
the testcase of PR30216, the loads that may alias with the store
to be hoisted are not visited.

The current patch visits all loads on the path from the store to
be hoisted to the hoisting position and uses the alias analysis
to ask whether the store may alias the load. I was not able to
use the MemorySSA functionality to ask for whether load and
store are clobbered: I'm not sure which function to call, so I
used a call to AA->isNoAlias().

Store past store is still working as before using a MemorySSA
query: I added an extra test to pr30216.ll to make sure store
past store does not regress.

Tested on x86_64-linux with check and a test-suite run.

Diff Detail

Repository
rL LLVM

Event Timeline

sebpop updated this revision to Diff 74255.Oct 11 2016, 8:30 AM
sebpop retitled this revision from to GVN-hoist: fix store past load dependence analysis (PR30216, PR30499).
sebpop updated this object.
sebpop added a reviewer: dberlin.
sebpop updated this revision to Diff 74281.Oct 11 2016, 11:52 AM

Updated to use MemorySSA.cpp:instructionClobbersQuery().
Thanks Danny for insisting on properly fixing this.

The way diff and phabricator displays the MemorySSA.cpp change is strange:
all I did is move getLoadReorderability() and instructionClobbersQuery() up in the llvm namespace, all the rest remains in place.
As the amount of text remaining in place is less than what moves, diff decided to display the complement.

dberlin accepted this revision.Oct 11 2016, 6:23 PM
dberlin edited edge metadata.
dberlin added inline comments.
llvm/include/llvm/Transforms/Utils/MemorySSA.h
977 ↗(On Diff #74281)

I would really rather not expose this version.
We should keep the interface as "memorydefs and memoryuses" as much as possible.

It also shouldn't be named instructionClobbersQuery.

So i would expect this to be something like

bool defClobbersUseOrDef(MemoryDef *MD, MemoryUseOrDef *MU, AliasAnalysis &AA);

Internally, it obviously will just call a version of instructionClobbersQuery, but that should be an API implementation detail.
I'm fine fixing this in a followup though.

This revision is now accepted and ready to land.Oct 11 2016, 6:23 PM
sebpop added inline comments.Oct 11 2016, 8:19 PM
llvm/include/llvm/Transforms/Utils/MemorySSA.h
977 ↗(On Diff #74281)

Committed the patch as r283965.
Committed the followup cleanup separately as r283967.

This revision was automatically updated to reflect the committed changes.