Bug 49018 - Inline assembly block executed outside conditional check with "-O1 -ftree-vrp"
Inline assembly block executed outside conditional check with "-O1 -ftree-vrp"
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: tree-optimization
4.6.0
: P3 normal
: 4.6.1
Assigned To: Richard Biener
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-17 09:57 UTC by Ted Cipicchio
Modified: 2011-05-18 13:34 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.6.1, 4.7.0
Known to fail: 4.6.0
Last reconfirmed: 2011-05-17 10:50:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Cipicchio 2011-05-17 09:57:02 UTC
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)
Comment 1 Richard Biener 2011-05-17 10:50:48 UTC
if-combine is doing this.  bb_no_side_effects_p returns true for the
basic-block with the asm.

Mine.
Comment 2 Richard Biener 2011-05-18 13:33:24 UTC
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
Comment 3 Richard Biener 2011-05-18 13:33:56 UTC
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
Comment 4 Richard Biener 2011-05-18 13:34:25 UTC
Fixed.