This is an archive of the discontinued LLVM Phabricator instance.

LVI: Add a per-value worklist limit to LazyValueInfo.
ClosedPublic

Authored by dberlin on Feb 8 2017, 6:00 AM.

Details

Summary

LVI is now depth first, which is optimal for iteration strategy in
terms of work per call. However, the way the results get cached means
it can still go very badly N^2 or worse right now. The overdefined
cache is per-block, because LVI wants to try to get different results
for the same name in different blocks (IE solve the problem
PredicateInfo solves). This means even if we discover a value is
overdefined after going very deep, it doesn't cache this information,
causing it to end up trying to rediscover it again and again. The
same is true for values along the way. In practice, overdefined
anywhere should mean overdefined everywhere (this is how, for example,
SCCP works).

Until we get around to reworking the overdefined cache, we need to
limit the worklist size we process. Note that permanently reverting
the DFS strategy exploration seems the wrong strategy (temporarily
seems fine if we really want). BFS is clearly the wrong approach, it
just gets luckier on some testcases. It's also very hard to design
an effective throttle for BFS. For DFS, the throttle is directly related
to the depth of the CFG. So really deep CFGs will get cutoff, smaller
ones will not. As the CFG simplifies, you get better results.
In BFS, the limit is it's related to the fan-out times average block size,
which is harder to reason about or make good choices for.

Bug being filed about the overdefined cache, but it will require major
surgery to fix it (plumbing predicateinfo through CVP or LVI).

Note: I did not make this number configurable because i'm not sure
anyone really needs to tweak this knob. We run CVP 3 times. On the
testcases i have the slow ones happen in the middle, where CVP is
doing cleanup work other things are effective at. Over the course of
3 runs, we don't see to have any real loss of performance.

I haven't gotten a minimized testcase yet, but just imagine in your
head a testcase where, going *up* the CFG, you have branches, one of
which leads 50000 blocks deep, and the other, to something where the
answer is overdefined immediately. BFS would discover the overdefined
faster than DFS, but do more work to do so. In practice, the right
answer is "once DFS discovers overdefined for a value, stop trying to
get more info about that value" (and so, DFS would normally cache the
overdefined results for every value it passed through in those 50k
blocks, and never do that work again. But it don't, because of the
naming problem)

Diff Detail

Repository
rL LLVM

Event Timeline

dberlin created this revision.Feb 8 2017, 6:00 AM
djasper added inline comments.Feb 8 2017, 6:08 AM
lib/Analysis/LazyValueInfo.cpp
659 ↗(On Diff #87641)

Wouldn't this lead to potentially adding Blocks to the cache where we haven't done any search (i.e. that got added after 499 processed values)? Is that a problem?

dberlin updated this revision to Diff 87646.Feb 8 2017, 6:33 AM

Add comments and make it fill in only the original stack values.

djasper accepted this revision.Feb 8 2017, 6:40 AM

lg

lib/Analysis/LazyValueInfo.cpp
661 ↗(On Diff #87646)

nit: naming-related.

668 ↗(On Diff #87646)

Have you intentionally changed this from DEBUG(dbgs() << ..)?

This revision is now accepted and ready to land.Feb 8 2017, 6:40 AM
dberlin marked 3 inline comments as done.Feb 8 2017, 6:54 AM
dberlin added inline comments.
lib/Analysis/LazyValueInfo.cpp
668 ↗(On Diff #87646)

No, sorry, that was just from the pastebin'ing i was doing with you offline. i'll put it back.

This revision was automatically updated to reflect the committed changes.
vitalybuka added inline comments.
llvm/trunk/lib/Analysis/LazyValueInfo.cpp
696

MSAN reported invalid memory access which was fixed with https://reviews.llvm.org/rL294572