This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: optimization/7325: Test "if ( a && b )" where a, b are 1-bit fields, could be better
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-gnats at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, falk at efalk dot org
- Cc: bangerth at dealii dot org
- Date: Wed, 8 Jan 2003 18:12:59 +0100
- Subject: Re: optimization/7325: Test "if ( a && b )" where a, b are 1-bit fields, could be better
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