optimization/7325: Test "if ( a && b )" where a, b are 1-bit fields, could be better
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Mon Jan 13 05:17:00 GMT 2003
falk@efalk.org wrote:
> However, if the test is
>
> if( foo->f1 && foo->f2 ) { ... }
>
> The code generated is
>
> if( (*foo & 3) == 3 ) { ... }
>
> which compiles as
>
> movb (%ebx), %al
> andl $3, %eax
> cmpb $3, %al
> jne .L34
> ...
>
> which is not so hot.
>
> It would be better if the test was translated to
>
> if( (*foo & ~3) == 0 ) { ... }
>
Argghh! This is just plain wrong! You are testing all the undefined bits
and not the relevant ones!
You could translate the test to
if( (*foo | ~3) == ~0 ) { ... }
which translates to
if( ~(*foo | ~3) == 0 ) { ... }
or something like this (modulo signed/unsigned issues)
if( (*foo | ~3)+1 == 0 ) { ... }
I don't know if one of those can be translated into faster code
than currently generated.
Regards,
Volker
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7325
More information about the Gcc-bugs
mailing list