[PATCH][RFC][match.pd] optimize (X & C) == N when C is power of 2
Segher Boessenkool
segher@kernel.crashing.org
Sat Jul 25 02:37:00 GMT 2015
On Fri, Jul 24, 2015 at 09:09:39AM +0100, Kyrill Tkachov wrote:
> This transformation folds (X % C) == N into
> X & ((1 << (size - 1)) | (C - 1))) == N
> for constants C and N where N is positive and C is a power of 2.
For N = 0 you can transform it to
((unsigned)X % C) == N
and for 0 < N < C you can transform it to
X > 0 && ((unsigned)X % C) == N (or X >= 0)
and for -C < N < 0 it is
X < 0 && ((unsigned)X % C) == N + C (or X <= 0)
and for other N it is
0.
For N not a constant, well, do you really care? :-)
(That second case might eventually fold to your original expression).
Segher
More information about the Gcc-patches
mailing list