[Bug c/40128] New: [ARM] Incorrect optimized code = -O2

2009-05-13 Thread al at alarsen dot net
This code:

# 1 fs.c
# 1 built-in
# 1 command line
# 1 fs.c

int foo(unsigned int bar)
{
 unsigned int mask = bar  0x8001;
 if (mask  0x8000)
  mask = 0x8000;
 return mask;
}

produces incorrect assembly code with -Os or -O2:

.file   fs.c
.text
.align  2
.global foo
.type   foo, %function
foo:
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
cmp r0, #0
andge   r0, r0, #-2147483648 == should be -2147483647
movlt   r0, #-2147483648
@ lr needed for prologue
bx  lr
.size   foo, .-foo
.ident  GCC: (GNU) 4.1.2

*** Command line: arm-v4t-linux-gnueabi -save-temps -O2 fs.c

*** Output:
Using built-in specs.
Target: arm-v4t-linux-gnueabi
Configured with:
/home/alarsen/projects/toolchain/OSELAS.Toolchain-1.1.1/build-cross/gcc-4.1.2/configure
--host=i686-host-linux-gnu --target=arm-v4t-linux-gnueabi
--prefix=/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18
--with-sysroot=/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/sysroot-arm-v4t-linux-gnueabi
--with-arch=armv4t --with-float=soft --with-fpu=vfp --disable-nls
--disable-multilib --enable-symvers=gnu --enable-__cxa_atexit --enable-shared
--enable-threads=posix --enable-languages=c,c++ --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.1.2

/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/libexec/gcc/arm-v4t-linux-gnueabi/4.1.2/cc1
-E -quiet -v fs.c -march=armv4t -mfloat-abi=soft -mfpu=vfp -O2 -fpch-preprocess
-o fs.i
ignoring nonexistent directory
/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/sysroot-arm-v4t-linux-gnueabi/usr/local/include
#include ... search starts here:
#include ... search starts here:

/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/lib/gcc/arm-v4t-linux-gnueabi/4.1.2/include

/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/lib/gcc/arm-v4t-linux-gnueabi/4.1.2/../../../../arm-v4t-linux-gnueabi/include

/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/sysroot-arm-v4t-linux-gnueabi/usr/include
End of search list.

/opt/OSELAS.Toolchain-1.1.1/arm-v4t-linux-gnueabi/gcc-4.1.2-glibc-2.5-kernel-2.6.18/libexec/gcc/arm-v4t-linux-gnueabi/4.1.2/cc1
-fpreprocessed fs.i -quiet -dumpbase fs.c -march=armv4t -mfloat-abi=soft
-mfpu=vfp -auxbase fs -O2 -version -o fs.s
GNU C version 4.1.2 (arm-v4t-linux-gnueabi)
compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu3).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2befb21690236570f62e4f3b11d6068c


-- 
   Summary: [ARM] Incorrect optimized code = -O2
   Product: gcc
   Version: 4.1.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: al at alarsen dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-v4t-linux-gnueabi


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



[Bug c/40128] [ARM] Incorrect optimized code = -O2

2009-05-13 Thread al at alarsen dot net


--- Comment #2 from al at alarsen dot net  2009-05-13 11:20 ---
Created an attachment (id=17856)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17856action=view)
preprocessed intermediate


-- 


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



[Bug c/40128] [ARM] Incorrect optimized code = -O2

2009-05-13 Thread al at alarsen dot net


--- Comment #3 from al at alarsen dot net  2009-05-13 13:37 ---
(In reply to comment #1)
 Can you try a newer version of the compiler ? 4.1.x is unsupported today. 
 
 I can see this is fixed on trunk and 4.3 as of revisions 147467 147441. An
 older version of 4.4 does not show this problem.

Thanks - I can confirm that 4.2.4 does not show the problem either.


-- 

al at alarsen dot net changed:

   What|Removed |Added

  Known to fail||4.1.2
  Known to work||4.2.4


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