[PATCH] D112080: [SCEV] Avoid long execution time in ScalarEvolution::isImpliedCond

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 19 08:20:38 PDT 2021


bjope created this revision.
bjope added reviewers: mkazantsev, fhahn.
Herald added a subscriber: hiraditya.
bjope requested review of this revision.
Herald added a project: LLVM.

As seen in PR51869 the ScalarEvolution::isImpliedCond function might
end up spending lots of time when doing the isKnownPredicate checks.

Calling isKnownPredicate for example result in isKnownViaInduction
being called, which might result in isLoopBackedgeGuardedByCond being
called, and then we might get one or more new calls to isImpliedCond.
Even if the scenario described here isn't an infinite loop, using
some random generated C programs as input indicates that those
isKnownPredicate checks quite often returns true. On the other hand,
the third condition that needs to be fulfilled in order to "prove
implications via truncation", i.e. the isImpliedCondBalancedTypes
check, is rarely fulfilled. So it seems like the analysis converge
to a result a bit quicker when doing the isImpliedCondBalancedTypes
check first.

This patch is mainly based on measuring compile time for the added
test case. But also checking some statistics for how often the
isKnownPredicate checks are true compared to how often the
isImpliedCondBalancedTypes check is true. The latter was measured
by for example using csmith to generate random C programs as input.
This might ofcourse be a bit biased if csmith programs often tend
to have the same kind of structure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112080

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/pr51869-scalar-evolution-prove-implications-via-truncation.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112080.380701.patch
Type: text/x-patch
Size: 9109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211019/ff334227/attachment.bin>


More information about the llvm-commits mailing list