re PR inline-asm/8832 (traditional "asm volatile" code is illegally optimized)

PR inline-asm/8832
	* tree.h (expand_asm): New prototype.
	* stmt.c (expand_asm): Set the MEM_VOLATILE_P flag if instructed
	to do so.
	* c-semantics (genrtl_asm_stmt): Pass the RID_VOLATILE qualifier
	down to expand_asm.
	* c-typeck.c (simple_asm_stmt): Set the RID_VOLATILE qualifier.
	* rtlanal.c (volatile_insn_p) [ASM_INPUT]: Test the MEM_VOLATILE_P flag.
	(volatile_refs_p) [ASM_INPUT]: Likewise.
	(side_effects_p) [ASM_INPUT]: Likewise.

From-SVN: r61099
This commit is contained in:
Eric Botcazou 2003-01-09 12:13:07 +01:00 committed by Eric Botcazou
parent f56e86bd9c
commit 4c46ea2353
8 changed files with 60 additions and 16 deletions

View File

@ -1,3 +1,16 @@
2003-01-09 Eric Botcazou <ebotcazou@libertysurf.fr>
PR inline-asm/8832
* tree.h (expand_asm): New prototype.
* stmt.c (expand_asm): Set the MEM_VOLATILE_P flag if instructed
to do so.
* c-semantics (genrtl_asm_stmt): Pass the RID_VOLATILE qualifier
down to expand_asm.
* c-typeck.c (simple_asm_stmt): Set the RID_VOLATILE qualifier.
* rtlanal.c (volatile_insn_p) [ASM_INPUT]: Test the MEM_VOLATILE_P flag.
(volatile_refs_p) [ASM_INPUT]: Likewise.
(side_effects_p) [ASM_INPUT]: Likewise.
Thu Jan 9 12:00:36 CET 2003 Jan Hubicka <jh@suse.cz>
* i386.md (*mul*): FIx constraints; remove confused comment; fix

View File

@ -749,7 +749,7 @@ genrtl_asm_stmt (cv_qualifier, string, output_operands,
emit_line_note (input_filename, lineno);
if (asm_input_p)
expand_asm (string);
expand_asm (string, cv_qualifier != NULL_TREE);
else
c_expand_asm_operands (string, output_operands, input_operands,
clobbers, cv_qualifier != NULL_TREE,

View File

@ -6853,9 +6853,9 @@ simple_asm_stmt (expr)
{
tree stmt;
stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr,
NULL_TREE, NULL_TREE,
NULL_TREE));
/* Simple asm statements are treated as volatile. */
stmt = add_stmt (build_stmt (ASM_STMT, ridpointers[(int) RID_VOLATILE],
expr, NULL_TREE, NULL_TREE, NULL_TREE));
ASM_INPUT_P (stmt) = 1;
return stmt;
}

View File

@ -2237,7 +2237,6 @@ volatile_insn_p (x)
case REG:
case SCRATCH:
case CLOBBER:
case ASM_INPUT:
case ADDR_VEC:
case ADDR_DIFF_VEC:
case CALL:
@ -2248,6 +2247,7 @@ volatile_insn_p (x)
/* case TRAP_IF: This isn't clear yet. */
return 1;
case ASM_INPUT:
case ASM_OPERANDS:
if (MEM_VOLATILE_P (x))
return 1;
@ -2304,7 +2304,6 @@ volatile_refs_p (x)
case REG:
case SCRATCH:
case CLOBBER:
case ASM_INPUT:
case ADDR_VEC:
case ADDR_DIFF_VEC:
return 0;
@ -2313,6 +2312,7 @@ volatile_refs_p (x)
return 1;
case MEM:
case ASM_INPUT:
case ASM_OPERANDS:
if (MEM_VOLATILE_P (x))
return 1;
@ -2368,7 +2368,6 @@ side_effects_p (x)
case PC:
case REG:
case SCRATCH:
case ASM_INPUT:
case ADDR_VEC:
case ADDR_DIFF_VEC:
return 0;
@ -2391,6 +2390,7 @@ side_effects_p (x)
return 1;
case MEM:
case ASM_INPUT:
case ASM_OPERANDS:
if (MEM_VOLATILE_P (x))
return 1;

View File

@ -1098,18 +1098,26 @@ n_occurrences (c, s)
}
/* Generate RTL for an asm statement (explicit assembler code).
BODY is a STRING_CST node containing the assembler code text,
or an ADDR_EXPR containing a STRING_CST. */
STRING is a STRING_CST node containing the assembler code text,
or an ADDR_EXPR containing a STRING_CST. VOL nonzero means the
insn is volatile; don't optimize it. */
void
expand_asm (body)
tree body;
expand_asm (string, vol)
tree string;
int vol;
{
if (TREE_CODE (body) == ADDR_EXPR)
body = TREE_OPERAND (body, 0);
rtx body;
emit_insn (gen_rtx_ASM_INPUT (VOIDmode,
TREE_STRING_POINTER (body)));
if (TREE_CODE (string) == ADDR_EXPR)
string = TREE_OPERAND (string, 0);
body = gen_rtx_ASM_INPUT (VOIDmode, TREE_STRING_POINTER (string));
MEM_VOLATILE_P (body) = vol;
emit_insn (body);
clear_last_expr ();
}

View File

@ -1,3 +1,7 @@
2003-01-09 Eric Botcazou <ebotcazou@libertysurf.fr>
gcc.dg/old-style-asm-1.c: New test.
2003-01-09 Richard Sandiford <rsandifo@redhat.com>
* gcc.c-torture/compile/20030109-1.c: New test.

View File

@ -0,0 +1,19 @@
/* PR inline-asm/8832 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* Verify that GCC doesn't optimize
old style asm instructions. */
void foo(int v)
{
if (v)
asm ("dummy1");
asm ("dummy2");
if (v)
asm ("dummy3");
}
/* { dg-final { scan-assembler "L2" } } */

View File

@ -2835,7 +2835,7 @@ extern void expand_decl_init PARAMS ((tree));
extern void clear_last_expr PARAMS ((void));
extern void expand_label PARAMS ((tree));
extern void expand_goto PARAMS ((tree));
extern void expand_asm PARAMS ((tree));
extern void expand_asm PARAMS ((tree, int));
extern void expand_start_cond PARAMS ((tree, int));
extern void expand_end_cond PARAMS ((void));
extern void expand_start_else PARAMS ((void));