This is an archive of the discontinued LLVM Phabricator instance.

[SCEV][NFC] Introduce isSignedDivisorOf function in SCEV
AbandonedPublic

Authored by mkazantsev on Oct 25 2017, 6:24 AM.

Details

Reviewers
sanjoy
anna
reames
Summary

Adds a function that checks whether one SCEV provably divides by other without
remainder if both values are treated as signed. No usage of the function comes
with this patch.

Diff Detail

Event Timeline

mkazantsev created this revision.Oct 25 2017, 6:24 AM
sanjoy requested changes to this revision.Oct 25 2017, 10:49 AM
sanjoy added inline comments.
lib/Analysis/ScalarEvolution.cpp
8963

This is really isUnsignedDivisorOf.

8973

If this is needed, you should add it to getURemExpr.

8976

Why do you deal with positive values only?

This revision now requires changes to proceed.Oct 25 2017, 10:49 AM
mkazantsev planned changes to this revision.Oct 26 2017, 12:04 AM

Going to add some stuff to make clear distinction between signed and unsigned division.

lib/Analysis/ScalarEvolution.cpp
8963

Not really. We can operate with negative values, for example of S = 0 or S = Divisor or Divisor = 1. I also think that it will be OK to return true for Divisor = -1 and S = -Divisor, and this is not be true in unsigned division. I am going to add these cases.

8973

This is only needed to work with negative values in some particular cases. getURemExpr interprets all as positive. I want isDivisorOf(-5, 5) be true, but (UINT_MAX - 4) urem 5 = 1.

mkazantsev edited edge metadata.
mkazantsev retitled this revision from [SCEV][NFC] Introduce isDivisorOf function in SCEV to [SCEV][NFC] Introduce isSignedDivisorOf function in SCEV.
mkazantsev edited the summary of this revision. (Show Details)

Hi Max,

Do you mind giving an overview of how you're going to use this?

include/llvm/Analysis/ScalarEvolution.h
685

s/provably divides/provably signed divides/

The general idea is that I plan to factor out concept of SCEV range (which is basically a tripple Begin, End, Step) into an utility class. The concept of such range is used in IRCE, Loop Predication and some other passes, each of them has its own implementation of basic stuff (such as intersection, contains check etc).

As one of pieces of this work, I want to implement intersection of ranges with step different from 1. At least we can handle simple cases: for example intersection of range Begin = 0, End = 100, Step = 5 and range Begin = 0, End = 100, Step = 10 is Begin = 0, End = 100, Step = 10.

This particular function (and its unsigned analogue) will be used like following: given 2 ranges with steps S1 and S2, and S1 divides by S2, and both Begin1, Begin2 have the same remainder mod S1, then their intersection is a range with Begin = max(Begin1, Begin2) and Step = S1.

I'm ok with this patch to not be merged until its application is implemented.

I'm ok with this patch to not be merged until its application is implemented.

I think we should wait to review this till rest of the code is written.

mkazantsev planned changes to this revision.Nov 6 2017, 8:36 PM

Put under rug until it's needed.

mkazantsev abandoned this revision.Nov 12 2017, 8:39 PM