This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Do not use induction in isKnownPredicate for simplification umax
ClosedPublic

Authored by skatkov on Apr 25 2018, 1:23 AM.

Details

Summary

During simplification umax we trigger isKnownPredicate twice. As a first attempt it
tries the induction. To do that it tries to get post increment of SCEV.
Re-writing the SCEV may result in simplification of umax. If the SCEV contains a lot
of umax operations this recursion becomes very slow.

The added test demonstrates the slow behavior.

To resolve this we use only simple ways to check whether the predicate is known.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Apr 25 2018, 1:23 AM
lebedev.ri added inline comments.
include/llvm/Analysis/ScalarEvolution.h
884 ↗(On Diff #143869)

s/Do not/Does not/ ?

1864 ↗(On Diff #143869)

Same

skatkov updated this revision to Diff 143870.Apr 25 2018, 2:00 AM

Would removing 'isKnownViaInduction' have any impact of the number of cases 'analyzeable by scev?

lib/Analysis/ScalarEvolution.cpp
8729 ↗(On Diff #143869)

Hi Serguei.

I tried to trace the split and code duplication, and I think it would probably be simpler to combine 'isKnownPredicateWithoutInduction' and 'isKnownPredicateWithoutInductionHelper' into just one function (if that's possible).

Would removing 'isKnownViaInduction' have any impact of the number of cases 'analyzeable by scev?

As I understand it should not.
We will not be able to simplify umax in case it could be simplified before due to usage of induction but late analysis should not in general suffer from that.

But let's wait for Sanjoy's opinion on that.

lib/Analysis/ScalarEvolution.cpp
8729 ↗(On Diff #143869)

Are you ok that we will have a code duplication in isKnownPredicateWithoutInduction and isKnownPredicate?

javed.absar added inline comments.Apr 25 2018, 2:18 AM
lib/Analysis/ScalarEvolution.cpp
8729 ↗(On Diff #143869)

Yes I think that would be better for readability.

skatkov updated this revision to Diff 144279.Apr 26 2018, 9:56 PM

@sanjoy , please take a look.

I'm a bit worried about adding yet another IsKnownViaXXX codepath (there are already too many!). Can we be a bit smarter in isKnownPredicate so that it avoids the recursive compile time blowup? If that's not possible, can we instead push the logic in isKnownPredicateWithoutInduction into isKnownViaNonRecursiveReasoning?

mkazantsev added inline comments.May 2 2018, 7:20 PM
lib/Analysis/ScalarEvolution.cpp
8797 ↗(On Diff #144279)

This can invoke isKnownPredicate and isKnownViaInduction from inside. And we will have the same problem again. I suggest invoking non-recursive reasoning check from umax/smax.

skatkov updated this revision to Diff 144980.May 2 2018, 9:42 PM

Agreed with Max. Restriction of recursion between isKnownPredicate and simplification of umax is too complex.

@sanjoy, are you ok with the last change?

sanjoy accepted this revision.May 8 2018, 9:47 PM

lgtm

test/Analysis/IVUsers/deep_recursion_in_scev.ll
9 ↗(On Diff #144980)

Minor nit: this test can probably be cleaned up a bit. For instance, instead of the volatile load you can pass in %tmp as a parameter, and you can remove the addressspace qualifiers.

This revision is now accepted and ready to land.May 8 2018, 9:47 PM
This revision was automatically updated to reflect the committed changes.