------- Comment #4 from zsojka at seznam dot cz  2010-09-07 21:50 -------
However, this optimization in RTL doesn't happen in all cases. For x86_64-linux
(with or without -m32):

----- testcase.c -----
_Bool foo(unsigned i)
{
        return (i >> 5) > 10;
}

_Bool bar(unsigned i)
{
        return i > (10 << 5);
}

int fooi(unsigned i)
{
        return (i >> 5) > 10;
}

int bari(unsigned i)
{
        return i > (10 << 5);
}
----------------------

Compiled with:
$ gcc-4.6.0-pre9999 tst6.c -O3 -S -m32 -fomit-frame-pointer
(svn r162190)

Results in:
foo:
        movl    4(%esp), %eax
        shrl    $5, %eax
        cmpl    $10, %eax
        seta    %al
        ret
bar:
        cmpl    $320, 4(%esp)
        seta    %al
        ret
fooi:
        movl    4(%esp), %eax
        shrl    $5, %eax
        cmpl    $10, %eax
        seta    %al
        movzbl  %al, %eax
        ret
bari:
        xorl    %eax, %eax
        cmpl    $320, 4(%esp)
        seta    %al
        ret

When compiled with -m64 it gets a bit better because parameter is in edi
instead of in stack, but the problem is still there. Should I open separate PR
for this?


-- 

zsojka at seznam dot cz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zsojka at seznam dot cz


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

Reply via email to