In the following test case, the int3 instruction inserted by the assertion macro is executed before any conditional check is performed when compiled with "-O1 -ftree-vrp". Without -ftree-vrp (as well as "-O2 -fno-tree-vrp"), the instructions are ordered as expected. $ cat asmvolatiletest.c #include <stdio.h> #define CUSTOM_ASSERT( X ) if( !( X ) ) { __asm__ __volatile__ ( "int3" ); } void testFunction( unsigned int a, unsigned int b ) { CUSTOM_ASSERT( a >= b ); if( a < b ) { printf( "Error: %u < %u\n", a, b ); } } $ gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.0/lto-wrapper Target: x86_64-mandriva-linux-gnu Configured with: ./configure --build=x86_64-mandriva-linux-gnu --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib64 --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --x-includes=/usr/include --x-libraries=/usr/lib64 --disable-libgcj --with-cloog --with-ppl --enable-cloog-backend=ppl --disable-libssp --disable-libunwind-exceptions --disable-werror --enable-__cxa_atexit --enable-bootstrap --enable-checking=release --enable-gnu-unique-object --enable-languages=c,ada,c++,fortran,go,lto,objc,obj-c++ --enable-linker-build-id --enable-plugin --enable-shared --enable-threads=posix --with-system-zlib --with-bugurl=https://qa.mandriva.com/ --with-tune=generic --with-arch_32=i686 --host=x86_64-mandriva-linux-gnu --target=x86_64-mandriva-linux-gnu Thread model: posix gcc version 4.6.0 20110513 (prerelease) (GCC)
if-combine is doing this. bb_no_side_effects_p returns true for the basic-block with the asm. Mine.
Author: rguenth Date: Wed May 18 13:33:21 2011 New Revision: 173861 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173861 Log: 2011-05-18 Richard Guenther <rguenther@suse.de> PR tree-optimization/49018 * gimple.c (gimple_has_side_effects): Volatile asms have side-effects. * tree-ssa-ifcombine.c (bb_no_side_effects_p): Use gimple_has_side_effects. Modified: trunk/gcc/ChangeLog trunk/gcc/gimple.c trunk/gcc/tree-ssa-ifcombine.c
Author: rguenth Date: Wed May 18 13:33:53 2011 New Revision: 173862 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173862 Log: 2011-05-18 Richard Guenther <rguenther@suse.de> PR tree-optimization/49018 * gimple.c (gimple_has_side_effects): Volatile asms have side-effects. * tree-ssa-ifcombine.c (bb_no_side_effects_p): Use gimple_has_side_effects. Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/gimple.c branches/gcc-4_6-branch/gcc/tree-ssa-ifcombine.c
Fixed.