[PATCH] D39954: [IRCE] Smart range intersection

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 02:57:56 PST 2017


mkazantsev added inline comments.


================
Comment at: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp:1658
+           "We can only substract from values in [0; SINT_MAX]!");
+    if (IsLatchSigned) {
+      // X is a number from signed range, Y is interpreted as signed.
----------------
mkazantsev wrote:
> anna wrote:
> > mkazantsev wrote:
> > > anna wrote:
> > > > To clarify: In both cases - signed and unsigned latch, the SCEV subtraction and rules you have below will always give us a value in range [0, SINT_MAX], i.e. we will never cross the signed border.
> > > > Here we are just "strengthening" the range and using unambiguous values for range intersection later on IRCE. 
> > > It is not true. If we substract `-5` from `SINT_MAX` in unsigned case, we have a value greater than `SINT_MAX`.
> > err.. I'm not sure what I'm missing. In the case you state, X = SINT_MAX, and Y = -5, latch is unsigned.
> > XMinusSIntMax = 0.
> > Y s< XMinusSIntMax ( i.e. -5 s< 0), i.e. it satisfies Rule 3.
> > So, what we are returning here is X - (XMinusSintMax) = X = SINT_MAX. 
> > 
> > 
> > In other words, I think, if M = -5, and upperLimit = SINT_MAX, latch is unsigned, what we want the safe iteration space to be is [0, SINT_MAX + 5]. 
> > So what am I missing?
> > 
> That `Y s< XMinusSIntMax ( i.e. -5 s< 0)` is a rule for signed latch.
> 
> Rules for unsigned latch are in `else` branch of this `if` :) `Y = -5` goes under `Rule 1: Y <s 0 ---> Y`. `SINT_MAX - (-5) = SINT_MAX + 5` which is still a positive value in unsigned iteration space.
In other words, for `Y = -5`, Range Check range `[0, SINT_MAX)`, unsigned latch we have result `[5, SINT_MAX + 5)` according to `Rule 1` for unsigned latches.


https://reviews.llvm.org/D39954





More information about the llvm-commits mailing list