This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/20517] New: bit shift/mask optimization potential
- From: "Thomas dot Koenig at online dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Mar 2005 13:17:21 -0000
- Subject: [Bug middle-end/20517] New: bit shift/mask optimization potential
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
$ cat shift.c
#include <stdio.h>
#define OFFSET 4
#define MASK 0xf0
int main()
{
unsigned int f,g;
scanf("%u",&f);
if ((f & MASK) >> OFFSET == 1) {
printf("success\n");
}
return 0;
}
$ gcc -S -O2 -fdump-tree-optimized shift.c
$ tail -20 shift.c.t66.optimized
unsigned int g;
unsigned int f;
int D.1807;
unsigned int D.1806;
unsigned int D.1805;
unsigned int f.10;
<bb 0>:
scanf (&"%u"[0], &f);
if ((f & 240) >> 4 == 1) goto <L0>; else goto <L1>;
<L0>:;
printf (&"success\n"[0]);
<L1>:;
return 0;
}
$ gcc -v
Using built-in specs.
Target: ia64-unknown-linux-gnu
Configured with: ../gcc-4.1-20050306/configure --prefix=/home/zfkts
--enable-languages=c,f95 --disable-optimization
Thread model: posix
gcc version 4.1.0 20050306 (experimental)
The expression (f & 0xf0) >> 4 == 1 could be optimized
to f & 0xf == 1 << 4.
Code like that occurs in the libgfortan library.
--
Summary: bit shift/mask optimization potential
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Thomas dot Koenig at online dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20517