[Bug rtl-optimization/31271] New: Missing simple optimization

matt at 3am-software dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 19 22:22:00 GMT 2007


The following shows a missing easy optimization for GCC:

int
in_canforward(unsigned int in)
{
        if ((in & ~0xffffff0f) == 0xf0 || (in & ~0xffffff0f) == 0xe0)
                return 0;
        return 1;
}

results in (@ -O2):

in_canforward:
        andl    $240, %edi
        cmpl    $240, %edi
        sete    %al
        cmpl    $224, %edi
        sete    %dl
        orl     %edx, %eax
        xorl    $1, %eax
        movzbl  %al, %eax
        ret

given that 0xf0 and 0xe0 only differ by one bit, there is no reason to test for
that bit so the comparision could be: (in & 0xffffff1f) == 0xe0.  More
generally
the optimization is:

given           (x & m) == a0 || (x & m) == a1
where m, a0, and a1 are all constant
let             b = (a0 ^ a1)
then if         (b & (b - 1)) == 0 [b is a power of 2]
rewrite to:     (x & (m|b)) == (a0 & ~b)


-- 
           Summary: Missing simple optimization
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matt at 3am-software dot com
 GCC build triplet: x86_64--netbsd
  GCC host triplet: x86_64--netbsd
GCC target triplet: x86_64--netbsd


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31271



More information about the Gcc-bugs mailing list