Tested with:

trunk r149624
# ./gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++
--prefix=/mnt/svn/gcc-trunk/build/
Thread model: posix
gcc version 4.5.0 20090714 (experimental) (GCC)

and gentoo's 4.4.0, 4.5_alpha20090709

The following code is miscompiled
------------------------
// command line: gcc tst.c -c -o tst.o -O1
// or: with -m32
int f3(int i) {
        return (i < 4 && i >= 0) ? i : 4;
}
------------------------

Resulting (relevant) asm is:
------------------------
f3:
.LFB0:
        .cfi_startproc
        cmpl    $4, %edi
        movl    $4, %eax
        cmovle  %edi, %eax
        ret
        .cfi_endproc
------------------------

For the following code:
------------------------
// command line: gcc tst.c -c -o tst.o -O1
// or: with -m32
#include <stdio.h>

int f3(int i) {
        return (i < 4 && i >= 0) ? i : 4;
}

int main() {
        printf("%d %d %d\n", f3(-1), f3(2), f3(5));
}
------------------------
Result is "-1 2 4", but it should be "4 2 4" (as it is with -O0)


-- 
           Summary: [4.4/4.5 Regression] wrong code for int-is-in-range test
                    at -O1 and above
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zsojka at seznam dot cz
  GCC host triplet: x86_64-pc-linux-gnu


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

Reply via email to