Bug 24146 - [4.0 Regression] ASMs with no output are not marked as volatile
Summary: [4.0 Regression] ASMs with no output are not marked as volatile
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.3
Assignee: Paolo Bonzini
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-09-30 13:42 UTC by Richard Biener
Modified: 2005-10-05 13:40 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail: 4.0.0
Last reconfirmed: 2005-09-30 14:11:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2005-09-30 13:42:51 UTC
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;
}
Comment 1 Andrew Pinski 2005-09-30 13:46:26 UTC
volatile is needed here.
Comment 2 Richard Earnshaw 2005-09-30 13:58:07 UTC
(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.
Comment 3 Andrew Pinski 2005-09-30 14:04:14 UTC

*** This bug has been marked as a duplicate of 19341 ***
Comment 4 Andrew Pinski 2005-09-30 14:07:01 UTC
I still say this is invalid.
Comment 5 Daniel Berlin 2005-09-30 14:07:14 UTC
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.


Comment 6 Paolo Bonzini 2005-09-30 14:10:42 UTC
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?
Comment 7 Andrew Pinski 2005-09-30 14:17:18 UTC
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.
Comment 8 Daniel Berlin 2005-09-30 14:18:10 UTC
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.


Comment 9 Andrew Pinski 2005-09-30 14:35:29 UTC
4.0 has also the latent bug.
Comment 10 Richard Henderson 2005-09-30 19:52:34 UTC
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~
Comment 11 GCC Commits 2005-10-05 12:17:20 UTC
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

Comment 12 Paolo Bonzini 2005-10-05 12:18:33 UTC
fix committed
Comment 13 Andrew Pinski 2005-10-05 12:19:35 UTC
(In reply to comment #12)
> fix committed

Except it is latent on the 4.0 branch too.
Comment 14 GCC Commits 2005-10-05 13:39:58 UTC
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

Comment 15 Andrew Pinski 2005-10-05 13:40:47 UTC
Fixed.