This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/38126] suboptimal code for (a && b || !a && !b)


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

--- Comment #4 from Steven Fuerst <svfuerst at gmail dot com> 2012-02-02 06:11:27 UTC ---
Two more cases for simple boolean logic optimizations.

gcc-4.7 produces with -O3 for

int test_and(long long x, long long y)
{
    return x && y;
}

    test   %rsi, %rsi
    setne  %dl
    xor    %eax, %eax
    test   %rdi, %rdi
    setne  %al
    and    %edx, %eax
    retq

Whereas this is faster:

    neg %rdi
    sbb %rdi, %rdi
    xor %eax, %eax
    and %rsi, %rdi
    setne %al
    retq

Also

int test_other(long long x, long long y)
{
    return !x && y; /* or !(x || !y) */
}

gives

    test   %rsi,%rsi
    setne  %dl
    xor    %eax,%eax
    test   %rdi,%rdi
    sete   %al
    and    %edx,%eax
    retq

when
    sub $1, %rsi
    sbb %rsi, %rsi
    xor %eax, %eax
    or %rdi, %rsi
    sete %al
    retq
is faster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]