This is an archive of the discontinued LLVM Phabricator instance.

Rewrite the use optimizer to be less memory intensive and 50% faster. Fixes PR28670
ClosedPublic

Authored by dberlin on Aug 1 2016, 1:52 PM.

Details

Summary

Rewrite the use optimizer to be less memory intensive and 50% faster.
Fixes PR28670

The new use optimizer works like a standard SSA renaming pass, storing
all possible versions a MemorySSA use could get in a stack, and just
tracking indexes into the stack.
This uses much less memory than caching N^2 alias query results.
It's also a lot faster.

The current version defers phi node walking to the normal walker.

Diff Detail

Event Timeline

dberlin updated this revision to Diff 66376.Aug 1 2016, 1:52 PM
dberlin retitled this revision from to Rewrite the use optimizer to be less memory intensive and 50% faster. Fixes PR28670.
dberlin updated this object.
dberlin added a reviewer: george.burgess.iv.
dberlin added a subscriber: llvm-commits.

Thanks for the patch!

Did you get to run this across llvm/etc., or would you like me to do so?

include/llvm/Transforms/Utils/MemorySSA.h
605

Can we change getBlockAccesses to just call this?

lib/Transforms/Utils/MemorySSA.cpp
1101

Nit: IsCall.

1191

Nit: Can we do const MemoryLocOrCall &?

1226

Looks like we can query the DT a lot less if we delete all VersionStack elements with the same BB as VersionStack.back(). Unsure how expensive those queries are, though, so it may or may not matter.

1231

I think

auto *MU = dyn_cast...;
if (!MU) {
  VersionStack.push_back(&MA);
  ++StackEpoch;
  continue;
}

//rest of the if block

is more readable

1270

Nit: Redundant parens

1292

Please remove the else, since we always break from the above if.

(Also, it looks like we can kill the if, since you're using cast)

1319

s/actually/actual/?

1330

Nit: useless struct

2125

Is this (and below) intentionally left in?

dberlin marked 10 inline comments as done.Aug 1 2016, 5:44 PM
dberlin added inline comments.
lib/Transforms/Utils/MemorySSA.cpp
1226

FWIW: It doesn't matter.
But i changed it.

dberlin updated this revision to Diff 66407.Aug 1 2016, 5:44 PM
dberlin marked an inline comment as done.
dberlin edited edge metadata.
  • Update for review comments
george.burgess.iv accepted this revision.Aug 1 2016, 6:40 PM
george.burgess.iv edited edge metadata.

LGTM; thanks again.

lib/Transforms/Utils/MemorySSA.cpp
1226

Yay for fast domtree ops!

This revision is now accepted and ready to land.Aug 1 2016, 6:40 PM
This revision was automatically updated to reflect the committed changes.
sebpop added a subscriber: sebpop.Aug 2 2016, 12:53 PM
sebpop added inline comments.
lib/Transforms/Utils/MemorySSA.cpp
1116

No need for "else" after return.

1139

Remove "else".

1246

s/if means/it means/

llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp
1152 ↗(On Diff #66491)

Would it be possible to merge the UseOptimizer with the renamePass?

1284 ↗(On Diff #66491)

This message needs some rewording.

1462 ↗(On Diff #66491)

If the renamePass (called just above) gets the right answer, there is no need to OptimizeUses ;-)
Maybe the logic from OptimizeUses can be merged in the renamePass.