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 target/30455] New: i386 generates unnecessary TEST instructions for arithmetic ops on memory


Consider the following function:

int add_zf(int *x, int y, int a, int b)
{
     if ((*x += y) == 0)
          return a;
     else
          return b;
}

Ideally, it should produce (modulo cmov verses branches / scheduling issues):

        addl    %esi, (%rdi)
        movl    %edx, %eax
        cmovne  %ecx, %eax
        ret

Instead, it produces:

        addl    (%rdi), %esi    # reversed
        movl    %edx, %eax
        testl   %esi, %esi      # unnecessary
        movl    %esi, (%rdi)    # unnecessary
        cmovne  %ecx, %eax
        ret

This is true of all flags and all arithmetic instructions (afaict).


-- 
           Summary: i386 generates unnecessary TEST instructions for
                    arithmetic ops on memory
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nmiell at comcast dot net


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


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