optimization/10362: Optimization with constant shifts and com pares fails on MIPS

Wolfgang Bangerth bangerth@ices.utexas.edu
Wed Apr 9 23:07:00 GMT 2003



> volatile unsigned long i;
> 
> void test(void)
> {
>   i = (((i & 0xf0) >> 4) >= 14); /* This one generates incorrect code with -O2 */
>   i = ((i & 0xf0) >= (14 << 4)); /* This is what the optimizer is trying to do */
> }

I think what the compiler actually does, is to transform it to 
  i = ((i & 0xf0) > (14<<4-1));
However, since the lowest 4 bits of the left hand side of the comparison 
are provably zero, this is equivalent to
  i = ((i & 0xf0) > (13<<4));

Do you have a value for "i", where you actually get a wrong comparison?

W.

-------------------------------------------------------------------------
Wolfgang Bangerth              email:            bangerth@ices.utexas.edu
                               www: http://www.ices.utexas.edu/~bangerth/




More information about the Gcc-bugs mailing list