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

            Bug ID: 124093
           Summary: [missed optimization] wrapped value range with <= is
                    not optimized
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nsz at gcc dot gnu.org
  Target Milestone: ---

at -O2 i expected the same code gen for foo*:

char foo1(unsigned char *p)
{
    return (unsigned)*p-2 <= 999;
}
char foo2(unsigned char *p)
{
    return (unsigned)*p-2 <= 253;
}
char foo3(unsigned char *p)
{
    return (unsigned)*p-2 <= -3u;
}
char foo4(unsigned char *p)
{
    return *p >= 2;
}

note: (unsigned)*p-2 is in [0,253] U [-2u,-1u],

with -O2 or -O3 on x86_64 i get

foo1:
        movzbl  (%rdi), %eax
        subl    $2, %eax
        cmpl    $999, %eax
        setbe   %al
        ret
foo2:
        movzbl  (%rdi), %eax
        subl    $2, %eax
        cmpl    $253, %eax
        setbe   %al
        ret
foo3:
        cmpb    $1, (%rdi)
        seta    %al
        ret
foo4:
        cmpb    $1, (%rdi)
        seta    %al
        ret

Reply via email to