[Bug middle-end/82853] Optimize x % 3 == 0 without modulo

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Sep 3 20:37:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82853

--- Comment #22 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, while it isn't correct to replace x % 3U == 1 by (x - 1) % 3U == 0, because
for x == 0 the test will yield a different value, as 0xffffffffU % 3U is 0 and
0 % 3U is also 0, x % 3U == 1 is equivalent to (x - 1) * 0xaaaaaaabU <=
0x55555554U, but x % 3U == 0 is equivalent to x * 0xaaaaaaabU <= 0x55555555U.
Now to see if something useful can be used also for the even divisors.


More information about the Gcc-bugs mailing list