This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/7325: Test "if ( a && b )" where a, b are 1-bit fields, could be better
- From: falk at efalk dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 16 Jul 2002 05:43:52 -0000
- Subject: c/7325: Test "if ( a && b )" where a, b are 1-bit fields, could be better
- Reply-to: falk at efalk dot org
>Number: 7325
>Category: c
>Synopsis: Test "if ( a && b )" where a, b are 1-bit fields, could be better
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Mon Jul 15 22:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: falk@efalk.org
>Release: 2.96
>Organization:
>Environment:
RH 7.2
>Description:
Imagine a structure like this:
typedef struct {
unsigned int f1:1 ;
unsigned int f2:1 ;
} Foo ;
This test:
if( foo->f1 || foo->f2 ) { ... }
Compiles into something like this:
if( (*foo & 3) != 0 ) { ... }
Generating code like this:
testb $3, (%ebx)
je .L34
...
Which is pretty good. 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 ) { ... }
which would compile something like this:
testb $-4, (%ebx)
jne .L35
...
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="tester.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="tester.c"
CnR5cGVkZWYgc3RydWN0IGZvbyB7CgkgIHVuc2lnbmVkIGludCBmMToxIDsKCSAgdW5zaWduZWQg
aW50IGYyOjEgOwoJfSBGb28gOwoKdm9pZApiYXIoRm9vICpmb28pCnsKCWlmKCBmb28tPmYxIHx8
IGZvby0+ZjIgKSBiYXIxKCkgOwoJaWYoIGZvby0+ZjEgJiYgZm9vLT5mMiApIGJhcjIoKSA7Cn0K