This is an archive of the discontinued LLVM Phabricator instance.

[DSE,MemorySSA] Limit walker steps.
ClosedPublic

Authored by fhahn on Aug 24 2020, 2:12 PM.

Details

Summary

For DSE with MemorySSA it is beneficial to only use a single step with
the MemorySSA walker, so we can better control the number of steps
together with other limits and also weed out invalid/unprofitable paths
early on.

This patch requires a follow-up patch to be most effective, which I will
share soon after putting this patch up.

This temporarily XFAIL's the limit tests, because we now explore more
MemoryDefs that may not alias/clobber the killing def. This will be
improved/fixed by the follow-up patch.

This patch allows us to aggressively cut down compile time, geomean
-O3 -0.64%, ReleaseThinLTO -1.65%, at the expense of fewer stores
removed. Subsequent patches will increase the number of removed stores
again, while keeping compile-time in check.

http://llvm-compile-time-tracker.com/compare.php?from=d8e3294118a8c5f3f97688a704d5a05b67646012&to=0a929b6978a068af8ddb02d0d4714a2843dd8ba9&stat=instructions

The new WalkerStepLimit might warrant an additional option.

Diff Detail

Event Timeline

fhahn created this revision.Aug 24 2020, 2:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2020, 2:12 PM
fhahn requested review of this revision.Aug 24 2020, 2:12 PM
asbirlea added inline comments.Aug 24 2020, 3:45 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1829

Use cl::opts instead of limit numbers in code (e.g. "SameBlockLimit")

1830

use: /*WalkerUpwardsLimit=*/0
remove ClobberSteps.

Why use 0?

2276

Can you make this a cl::opt?

fhahn updated this revision to Diff 287678.Aug 25 2020, 8:26 AM

Rebase, turn thresholds into options, use UpwardWalkingLimit = 1 instead of 0, add a few additional comments.

fhahn marked an inline comment as done.Aug 25 2020, 8:28 AM
fhahn added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1829

Done. Also added a comment on why there are different costs.

1830

The argument is taken by reference, and the walker decrements it as it goes along I think. I meant to use 1 as limit (single step), added a comment as to why. I think the behavior is actually the same whether 0 or 1 is passed, as I think if it is 0 initially it gets bumped to 1 internally.

2276

Turned into another option.

asbirlea added inline comments.Aug 25 2020, 2:32 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1830

Yes, I missed it needs a reference there.

You're right that 0 and 1 mean the same, I should have phrased the question clearer with what I meant.
If the cap you set is 0, this isn't getting more information than getDefiningAccess. The getClobberingAccess call should never reach the tryOptimizePhi call for the 0/1 caps.
If the intention is to deal with phi translation (as the comment says), you need a cap of 2+, and it will be dependent on the number of defs per block if it actually reaches the Phi.

fhahn updated this revision to Diff 287929.Aug 26 2020, 4:55 AM
fhahn marked an inline comment as done.

Drop unnecessary use of ClobberWalker.

fhahn added inline comments.Aug 26 2020, 5:02 AM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1830

Thanks for clarifying. Currently it appears that actually using the clobber walker incurs too much compile-time overhead without too much gains. By doing the walk ourselves, we can stop traversing non-profitable paths earlier, as is done in D86487.

I removed the getClobberingMemoryAccess call. In the future, it might be good to extend the code here to optimize memory defs & uses if possible based on the checks we have to do anyways. It would be great to get some input on that and potentially additional tricks we can apply to MemorySSA, but that would probably best after the switch, once we got a decent amount of testing.

I also renamed the Dom* variable names, as Earlier* seems more appropriate and the dominance relation is not really important here.

asbirlea accepted this revision.Aug 26 2020, 3:52 PM
asbirlea added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1830

sgtm, let's follow up on that.

This revision is now accepted and ready to land.Aug 26 2020, 3:52 PM
This revision was landed with ongoing or failed builds.Aug 27 2020, 2:04 AM
This revision was automatically updated to reflect the committed changes.