[Bug middle-end/44530] wrong code due to branch optimization

2010-06-14 Thread pinskia at gcc dot gnu dot org


--- Comment #4 from pinskia at gcc dot gnu dot org  2010-06-14 07:35 ---
  if ((unsigned int)(xCount + 32)  0x8000)

Yes even though the comparision is done in an unsigned type, the addition is
done in a signed type which means the overflow of that addition is undefined. 
So changing the code to be:
if (((unsigned int)xCount) + 32u  0x8000u)

Will fix the issue or use -fwrapv.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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



[Bug middle-end/44530] wrong code due to branch optimization

2010-06-13 Thread Daniel dot Davies at xerox dot com


--- Comment #1 from Daniel dot Davies at xerox dot com  2010-06-13 21:35 
---
Created an attachment (id=20905)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20905action=view)
Preprocessed source file


-- 


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



[Bug middle-end/44530] wrong code due to branch optimization

2010-06-13 Thread pinskia at gmail dot com


--- Comment #2 from pinskia at gmail dot com  2010-06-13 21:58 ---
Subject: Re:   New: wrong code due to branch optimization



Sent from my iPhone

On Jun 13, 2010, at 2:34 PM, Daniel dot Davies at xerox dot com
gcc-bugzi...@gcc.gnu.org 
  wrote:

 When compiled with -03, the attached file prints out an error  
 message due to
 incorrectly comparing xCount + 32  0x8000.  When compiled  
 with the
 default optimization, it prints out the correct message.


It sounds like the addition is overflowing and signed integer overflow  
is undefined. Use either -fwrapv or -fno-strict-overflow.


 $ gcc -v -save-temps -std=gnu99 -fno-strict-aliasing -funroll-loops
 -march=core2 -mfpmath=387 -ffloat-store -pedantic -Wall -W -Wstrict- 
 prototypes
 -Wpointer-arith -Wwrite-strings -Wcast-qual -Wmissing-prototypes -fPIC
 gcc450CompareBug.c
 Using built-in specs.
 COLLECT_GCC=gcc
 COLLECT_LTO_WRAPPER=/tool/gcc/4.5.0/i386-pc-solaris2.10/libexec/gcc/ 
 i386-pc-solaris2.10/4.5.0/lto-wrapper
 Target: i386-pc-solaris2.10
 Configured with: /tool/gcc/4.5.0/gcc-4.5.0/configure
 --prefix=/tool/gcc/4.5.0/i386-pc-solaris2.10 --with-gnu-as --with- 
 gnu-ld
 --disable-shared --enable-lto --with-libelf=/usr/local --enable-gold
 Thread model: posix
 gcc version 4.5.0 (GCC)
 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=gnu99' '-fno-strict- 
 aliasing'
 '-funroll-loops' '-march=core2' '-mfpmath=387' '-ffloat-store' '- 
 pedantic'
 '-Wall' '-W' '-Wstrict-prototypes' '-Wpointer-arith' '-Wwrite-strings'
 '-Wcast-qual' '-Wmissing-prototypes' '-fPIC'
 /tool/gcc/4.5.0/i386-pc-solaris2.10/libexec/gcc/i386-pc- 
 solaris2.10/4.5.0/cc1
 -E -quiet -v gcc450CompareBug.c -march=core2 -mfpmath=387 -std=gnu99  
 -pedantic
 -Wall -W -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast- 
 qual
 -Wmissing-prototypes -fno-strict-aliasing -funroll-loops -ffloat- 
 store -fPIC
 -fpch-preprocess -o gcc450CompareBug.i
 ignoring nonexistent directory
 /tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/../../../../i386-pc-solaris2.10/include
 #include ... search starts here:
 #include ... search starts here:
 /usr/local/include
 /tool/gcc/4.5.0/i386-pc-solaris2.10/include
 /tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/include

 /tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/include-fixed
 /usr/include
 End of search list.
 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=gnu99' '-fno-strict- 
 aliasing'
 '-funroll-loops' '-march=core2' '-mfpmath=387' '-ffloat-store' '- 
 pedantic'
 '-Wall' '-W' '-Wstrict-prototypes' '-Wpointer-arith' '-Wwrite-strings'
 '-Wcast-qual' '-Wmissing-prototypes' '-fPIC'
 /tool/gcc/4.5.0/i386-pc-solaris2.10/libexec/gcc/i386-pc- 
 solaris2.10/4.5.0/cc1
 -fpreprocessed gcc450CompareBug.i -quiet -dumpbase gcc450CompareBug.c
 -march=core2 -mfpmath=387 -auxbase gcc450CompareBug -pedantic -Wall -W
 -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast-qual
 -Wmissing-prototypes -std=gnu99 -version -fno-strict-aliasing - 
 funroll-loops
 -ffloat-store -fPIC -o gcc450CompareBug.s
 GNU C (GCC) version 4.5.0 (i386-pc-solaris2.10)
compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR  
 version 2.4.2,
 MPC version 0.8.2
 GGC heuristics: --param ggc-min-expand=100 --param ggc-min- 
 heapsize=131072
 GNU C (GCC) version 4.5.0 (i386-pc-solaris2.10)
compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR  
 version 2.4.2,
 MPC version 0.8.2
 GGC heuristics: --param ggc-min-expand=100 --param ggc-min- 
 heapsize=131072
 Compiler executable checksum: cf0046f5352e75464cfcf0489db9539c
 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=gnu99' '-fno-strict- 
 aliasing'
 '-funroll-loops' '-march=core2' '-mfpmath=387' '-ffloat-store' '- 
 pedantic'
 '-Wall' '-W' '-Wstrict-prototypes' '-Wpointer-arith' '-Wwrite-strings'
 '-Wcast-qual' '-Wmissing-prototypes' '-fPIC'

 /tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/../../../../i386-pc-solaris2.10/bin/as
 -v -V -Qy -s -o gcc450CompareBug.o gcc450CompareBug.s
 GNU assembler version 2.20 (i386-pc-solaris2.10) using BFD version  
 (GNU
 Binutils) 2.20
 COMPILER_PATH=/tool/gcc/4.5.0/i386-pc-solaris2.10/libexec/gcc/i386- 
 pc-solaris2.10/4.5.0/:/tool/gcc/4.5.0/i386-pc-solaris2.10/libexec/ 
 gcc/i386-pc-solaris2.10/4.5.0/:/tool/gcc/4.5.0/i386-pc-solaris2.10/ 
 libexec/gcc/i386-pc-solaris2.10/:/tool/gcc/4.5.0/i386-pc-solaris2.10/ 
 lib/gcc/i386-pc-solaris2.10/4.5.0/:/tool/gcc/4.5.0/i386-pc- 
 solaris2.10/lib/gcc/i386-pc-solaris2.10/:/tool/gcc/4.5.0/i386-pc- 
 solaris2.10/lib/gcc/i386-pc-solaris2.10/4.5.0/../../../../i386-pc- 
 solaris2.10/bin/:/usr/ccs/bin/
 LIBRARY_PATH=/tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/:/tool/gcc/4.5.0/i386-pc-solaris2.10/lib/gcc/i386- 
 pc-solaris2.10/4.5.0/../../../../i386-pc-solaris2.10/lib/:/tool/gcc/ 
 4.5.0/i386-pc-solaris2.10/lib/gcc/i386-pc- 
 solaris2.10/4.5.0/../../../:/lib/:/usr/lib/
 COLLECT_GCC_OPTIONS='-v' 

[Bug middle-end/44530] wrong code due to branch optimization

2010-06-13 Thread Daniel dot Davies at xerox dot com


--- Comment #3 from Daniel dot Davies at xerox dot com  2010-06-14 02:49 
---
Thank You!  Adding the -fwrapv flag fixed the problem.


-- 


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