On Fri, 14 Mar 2014, Prathamesh Kulkarni wrote:

On Fri, Mar 14, 2014 at 9:25 PM, Marc Glisse <marc.gli...@inria.fr> wrote:
On Fri, 14 Mar 2014, Prathamesh Kulkarni wrote:

The patterns mentioned in the links were:
a) (X >> CST1) >= CST2 -> X >= CST2 << CST1
however, an expression Y >= CST gets folded to Y > CST - 1
so the transform I wrote:
(X >> CST1) > CST2 -> X > CST2 << CST1

That's not the same, try X=1, CST1=1, CST2=0.
Ah yes. Shall following be correct ?
(X >> CST1) > CST2 -> X > ( (CST2 + 1) << CST1 ) - 1
Works correctly for X=1, CST1 = 1, CST2 = 0

Looks better. Though there is still the case where the new constant overflows, in which case we can fold the comparison to false.

b) (X & ~CST) == 0 -> X <= CST

Uh, that can't be true for all constants, only some with a very specific
shape (7 is 2^3-1).
Agreed. Shall the pattern be folded if CST is 2^(n-1) ?

Wrong parentheses. And I didn't really think about it, so that may not be the right test.

I think it would be a good idea to write, in comments, next to each non-trivial transformation, a short "proof" (at least some form of explanation). It would help people re-reading it later see quickly why the conditions are what they are.

--
Marc Glisse

Reply via email to