For the following testcase, the call to mpfr_test_init is optimized away at -O1 and up. Which is of course bogous(?). void mpfr_test_init (void); void mpfr_test_init () { do { int __cw = (0x037f & (~0x300)) | 0x200; __asm__ ("fldcw %0" : : "m" (__cw)); } while (0); } int main (void) { mpfr_test_init (); return 0; }
volatile is needed here.
(In reply to comment #1) > volatile is needed here. No, the manual says: An @code{asm} instruction without any output operands will be treated identically to a volatile @code{asm} instruction. So this insn should be kept even though it isn't explicitly volatile.
*** This bug has been marked as a duplicate of 19341 ***
I still say this is invalid.
Subject: Re: Optimizes away FPU control word store On Fri, 2005-09-30 at 13:58 +0000, rearnsha at gcc dot gnu dot org wrote: > ------- Additional Comments From rearnsha at gcc dot gnu dot org 2005-09-30 13:58 ------- > (In reply to comment #1) > > volatile is needed here. > > No, the manual says: > An @code{asm} instruction without any output operands will be treated > identically to a volatile @code{asm} instruction. > > So this insn should be kept even though it isn't explicitly volatile. > Then i guess we should teach the FE to just mark them volatile, so we don't have to worry about this in the middle end.
Richard Earnshaw is right; this is not a dup of PR19341. volatile-ness is about optimizing away the asm statement itself; PR19341 is about optimizing away code needed by the asm. Reopening. rth, should this be fixed in the front-end or in the gimplifier?
Hmm, the comment in c-typeck.c: /* Build an asm-expr, whose components are a STRING, some OUTPUTS, some INPUTS, and some CLOBBERS. The latter three may be NULL. SIMPLE indicates whether there was anything at all after the string in the asm expression -- asm("blah") and asm("blah" : ) are subtly different. We use a ASM_EXPR node to represent this. */ so maybe this is invalid after all.
Subject: Re: [4.0 Regression] Optimizes away FPU control word store On Fri, 2005-09-30 at 14:07 +0000, pinskia at gcc dot gnu dot org wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-30 14:07 ------- > I still say this is invalid. > well, that just makes you wrong. the docs clearly say it's supposed to be treated as volatile.
4.0 has also the latent bug.
Subject: Re: [4.0 Regression] Optimizes away FPU control word store On Fri, Sep 30, 2005 at 02:10:48PM -0000, bonzini at gcc dot gnu dot org wrote: > rth, should this be fixed in the front-end or in the gimplifier? Front end. It's a one liner in build_asm_expr. r~
Subject: Bug 24146 CVSROOT: /cvs/gcc Module name: gcc Changes by: bonzini@gcc.gnu.org 2005-10-05 12:17:16 Modified files: gcc : ChangeLog c-typeck.c gimplify.c gcc/cp : ChangeLog semantics.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg: asm-1.c pr21419.c Added files: gcc/testsuite/g++.dg/ext: asm7.C asm8.C gcc/testsuite/gcc.dg: asm-pr24146.c Log message: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * c-typeck.c (readonly_error): Handle USE being lv_asm. (build_asm_expr): Call it if outputs are read-only. * gimplify.c (gimplify_asm_expr): Remove former fix to PR 21419. cp: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * semantics.c (finish_asm_stmt): Call readonly_error if outputs are read-only. Set ASM_VOLATILE_P for asms without outputs. testsuite: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * g++.dg/ext/asm7.C: New. * g++.dg/ext/asm8.C: New. * gcc.dg/asm-1.c: Compile on all targets. * gcc.dg/asm-pr24146.c: New. * gcc.dg/pr21419.c: Adjust error messages. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.10087&r2=2.10088 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.480&r2=1.481 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.156&r2=2.157 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4912&r2=1.4913 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.490&r2=1.491 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6140&r2=1.6141 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/asm7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/asm8.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/asm-pr24146.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/asm-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr21419.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
fix committed
(In reply to comment #12) > fix committed Except it is latent on the 4.0 branch too.
Subject: Bug 24146 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: bonzini@gcc.gnu.org 2005-10-05 13:39:51 Modified files: gcc : ChangeLog c-typeck.c gimplify.c gcc/cp : ChangeLog semantics.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg: asm-1.c pr21419.c Added files: gcc/testsuite/g++.dg/ext: asm7.C asm8.C gcc/testsuite/gcc.dg: asm-pr24146.c Log message: gcc: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * c-typeck.c (readonly_error): Handle USE being lv_asm. (build_asm_expr): Call it if outputs are read-only. * gimplify.c (gimplify_asm_expr): Remove former fix to PR 21419. cp: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * semantics.c (finish_asm_stmt): Call readonly_error if outputs are read-only. Set ASM_VOLATILE_P for asms without outputs. testsuite: 2005-10-05 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/21419 PR tree-optimization/24146 PR tree-optimization/24151 * g++.dg/ext/asm7.C: New. * g++.dg/ext/asm8.C: New. * gcc.dg/asm-1.c: Compile on all targets. * gcc.dg/asm-pr24146.c: New. * gcc.dg/pr21419.c: Adjust error messages. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.447&r2=2.7592.2.448 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.419.2.13&r2=1.419.2.14 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.113.2.13&r2=2.113.2.14 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.116&r2=1.4648.2.117 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.463.2.10&r2=1.463.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.428&r2=1.5084.2.429 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/asm7.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/asm8.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/asm-pr24146.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/asm-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.166.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr21419.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2
Fixed.