From 4c46ea235323cd0283d998d9860d8596811a704c Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 9 Jan 2003 12:13:07 +0100 Subject: [PATCH] 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 --- gcc/ChangeLog | 13 +++++++++++++ gcc/c-semantics.c | 2 +- gcc/c-typeck.c | 6 +++--- gcc/rtlanal.c | 6 +++--- gcc/stmt.c | 24 ++++++++++++++++-------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/old-style-asm-1.c | 19 +++++++++++++++++++ gcc/tree.h | 2 +- 8 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/old-style-asm-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4055fa12832a..96ca06396ff3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2003-01-09 Eric Botcazou + + 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 * i386.md (*mul*): FIx constraints; remove confused comment; fix diff --git a/gcc/c-semantics.c b/gcc/c-semantics.c index 77d7384f9a2b..769c1165d4a3 100644 --- a/gcc/c-semantics.c +++ b/gcc/c-semantics.c @@ -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, diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index c5b4ecbf9d3e..87703a730795 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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; } diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c index 63d7feb60351..030682e43f90 100644 --- a/gcc/rtlanal.c +++ b/gcc/rtlanal.c @@ -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; diff --git a/gcc/stmt.c b/gcc/stmt.c index fbdf463ee571..ac0aa15bef29 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -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; + + 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 (gen_rtx_ASM_INPUT (VOIDmode, - TREE_STRING_POINTER (body))); + emit_insn (body); + clear_last_expr (); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f5d0134f2a1f..8063cf3a40db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-01-09 Eric Botcazou + + gcc.dg/old-style-asm-1.c: New test. + 2003-01-09 Richard Sandiford * gcc.c-torture/compile/20030109-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/old-style-asm-1.c b/gcc/testsuite/gcc.dg/old-style-asm-1.c new file mode 100644 index 000000000000..006cf0949b08 --- /dev/null +++ b/gcc/testsuite/gcc.dg/old-style-asm-1.c @@ -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" } } */ diff --git a/gcc/tree.h b/gcc/tree.h index 93a237f73f2d..6075d83b87f0 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -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)); -- 2.43.5