Bug 31271 - Missing simple optimization
Summary: Missing simple optimization
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-19 22:22 UTC by matt
Modified: 2007-03-20 10:39 UTC (History)
2 users (show)

See Also:
Host: x86_64--netbsd
Target: x86_64--netbsd
Build: x86_64--netbsd
Known to work:
Known to fail:
Last reconfirmed: 2007-03-20 10:39:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matt 2007-03-19 22:22:47 UTC
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)
Comment 1 Richard Biener 2007-03-20 10:39:11 UTC
Confirmed.  This is neither done at the tree nor at the rtl level.