gcc looks like it's omitting a simple optimization which can be done on logical operations.
/* Command line and output on a linux host */ [EMAIL PROTECTED]:~$ gcc -o test test.c -Os && ls -l test -rwxr-xr-x 1 engin engin 6461 2008-10-31 12:26 test [EMAIL PROTECTED]:~$ gcc -o test test.c -Os -DHAND_OPTIMIZED && ls -l test -rwxr-xr-x 1 engin engin 6365 2008-10-31 12:26 test [EMAIL PROTECTED]:~$ gcc -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7 /* Command line and ouput on cygwin */ [EMAIL PROTECTED] /cygdrive/c/Users/Engin/Code/mmc $ gcc -o test test.c -Os && ls -l test -rwxr-xr-x 1 Engin None 9068 Oct 31 13:42 test [EMAIL PROTECTED] /cygdrive/c/Users/Engin/Code/mmc $ gcc -o test test.c -Os -DHAND_OPTIMIZED&& ls -l test -rwxr-xr-x 1 Engin None 8556 Oct 31 13:43 test [EMAIL PROTECTED] /cygdrive/c/Users/Engin/Code/mmc $ gcc -v Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-pref ix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share /info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-ver sion-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpre ter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjl j-exceptions --enable-hash-synchronization --enable-libstdcxx-debug Thread model: posix gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) /************* CODE ******************/ volatile int* foo = (volatile int*)0x23232322; int main(void) { int a, b, c, d, e, f, g, h, z = 0; a = *foo; b = *foo; c = *foo; d = *foo; e = *foo; f = *foo; g = *foo; h = *foo; #ifndef HAND_OPTIMIZED if ( (f && c && b && a) || (f && e && d && a) || (f && e && h && a) || (g && c && b && a) || (g && e && d && a) || (g && e && h && a) ) #else if ((f||g) && a && ( (b&&c) || ((d||h)&& e))) #endif { z= a + b + c; h=12; d= h + b + c; e=45; } e=z*2+d+a; *foo = e; while(1) { *foo = e; } } -- Summary: GCC Overlooks Logical Operation Optimizations ? Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: engin at bzzzt dot biz http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37979