https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82853
--- Comment #11 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Wilco from comment #9) > It works for any C where (divisor*C) MOD 2^32 == 1 (or -1). For x%3==0, i.e. z==0 for x==3*y+z with 0<=y<55555556 and 0<=z<3. Indeed, x*0xaaaaaaab==y+z*0xaaaaaaab is in the right range precisely for z==0 and the same can be done for any odd number. > You can support any kind of comparison, it doesn't need to be with 0 (but > zero is the easiest). Any ==cst will yield a range test. It is less obvious that inequalities are transformed to a contiguous range... (try x%7<3 maybe) > I forgot whether I made it work for signed too, but it's certainly > possible to skip the sign handling in x % 4 == 0 even if x is signed. 4 is a completely different story, as a power of 2.