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 rtl-optimization/58195] New: Missed optimization opportunity when returning a conditional


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

            Bug ID: 58195
           Summary: Missed optimization opportunity when returning a
                    conditional
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: warp at iki dot fi

When compiling the following function:

int a(int input)
{
    return input == 0 ? 0 : -input;
}

gcc is unable to see that the conditional and returning 0 can be optimized
away, producing:

        movl    %edi, %edx
        xorl    %eax, %eax
        negl    %edx
        testl   %edi, %edi
        cmovne  %edx, %eax
        ret

For the record, I found out the above when I was testing what gcc would do with
this function:

int a(int input)
{
    int value = 0;
    for(int n = input; n != 0; ++n)
        ++value;
    return value;
}

gcc is able to optimize that into the same asm code as above, but no further
(not even if the conditional is written explicitly, as written in the first
function above.)


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