This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]