https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67998

            Bug ID: 67998
           Summary: redundant test for 0 when also checking inequality
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rv at rasmusvillemoes dot dk
  Target Milestone: ---

int f(unsigned a, unsigned b)
{
        if (!a || b >= a)
                return 5;
        return 2;
}

compiles to

f(unsigned int, unsigned int):
        testl   %edi, %edi
        je      .L3
        cmpl    %esi, %edi
        jbe     .L3
        movl    $2, %eax
        ret
.L3:
        movl    $5, %eax
        ret

The first test is redundant, since if a is zero, the inequality is guaranteed
to hold.

Reply via email to