The following code: #include <stdio.h>
float floatsisf(int x) { float ans = 0.5F; long lexp = 24; unsigned long frac = x; unsigned long norm = 0x800000; unsigned long xint; for (; frac < norm; frac <<= 1) --lexp; xint = (unsigned long)frac; (((unsigned short *)(char *)&(ans)))[1] = (((unsigned short *)(char *)&(ans)))[1] & 0xff80 | ((xint) >> 16 ) & 0x007f; (((unsigned short *)(char *)&(ans)))[0] = (xint) & 0xffff; fprintf(stderr,"scale got (%f)\n",ans); return ans; } main(){ int i; for(i=1;i<10;i++) floatsisf(i); } uses an obscure way to communicate with alias analyzer. The way I understand the original intent, once you cast &ans to (char *), alias analyzer should treat it as "char" == "alias everything" case. With GCC 3.3.3 and 3.4.6 that was the case. Starting with GCC 4.4.0 it does not - the leftmost (unsigned short *) cast seems to permit speculation about the two references, resulting in a wrong code generated. More details: >/xxx/x86_gcc_4.4/bin/bin/gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --enable-threads=posix --prefix=/prj/dsp/qdsp6_aus/users/slarin/x86_gcc_4.4/bin --enable-languages=c,c++ --disable-checking Thread model: posix gcc version 4.4.0 (GCC) >/xxx/x86_gcc_4.4/bin/bin/gcc -O1 test.c >./a.out scale got (0.500000) scale got (0.500000) scale got (0.750000) scale got (0.500000) scale got (0.625000) scale got (0.750000) scale got (0.875000) scale got (0.500000) scale got (0.562500) >/xxx/x86_gcc_4.4/bin/bin/gcc -O1 -fstrict-aliasing test.c sla...@l1:~/test_gcc/qcc/bad> ./a.out scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) scale got (0.500000) Same exercise with: > gcc -v Reading specs from /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada --disable-checking --libdir=/usr/lib64 --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit x86_64-suse-linux Thread model: posix gcc version 3.3.3 (SuSE Linux) ... yields correct results either way. -- Summary: Alias stacked type cast interpretation regression Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sergei_lus at yahoo dot com GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41072