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

Reply via email to