The shift isn't necessary.  This could have
been re-coded as

    return (a-b)<2;

with -fstrict-overflow.

$ cat ga.c
int foo(int a, int b)
{
    return (a-b)*4 < 8;
}
$ gcc -S -O2 -fstrict-overflow ga.c
$ cat ga.s
        .file   "ga.c"
        .text
        .p2align 4,,15
.globl foo
        .type   foo, @function
foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        subl    12(%ebp), %eax
        popl    %ebp
        sall    $2, %eax
        cmpl    $7, %eax
        setle   %al
        movzbl  %al, %eax
        ret
        .size   foo, .-foo
        .ident  "GCC: (GNU) 4.4.0 20090221 (experimental)"
        .section        .note.GNU-stack,"",@progbits


-- 
           Summary: -fstrict-overflow misses multiply in comparison
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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

Reply via email to