From a6c14a644cb2a52baecf1f74d128297352fd360d Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sat, 26 Jul 2003 08:53:14 -0700 Subject: [PATCH] re PR inline-asm/11676 (operand to volatile asm incorrectly removed) PR inline-asm/11676 * cse.c (count_reg_usage): Handle asm_operands properly. From-SVN: r69816 --- gcc/ChangeLog | 5 +++++ gcc/cse.c | 10 ++++++++++ gcc/testsuite/gcc.dg/asm-8.c | 9 +++++++++ gcc/testsuite/gcc.dg/i386-asm-1.c | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/asm-8.c create mode 100644 gcc/testsuite/gcc.dg/i386-asm-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f1aaa6d1a06..b2f70286a07 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-07-26 Richard Henderson + + PR inline-asm/11676 + * cse.c (count_reg_usage): Handle asm_operands properly. + 2003-07-26 Roger Sayle * builtins.def (DEF_FALLBACK_BUILTIN): Delete. diff --git a/gcc/cse.c b/gcc/cse.c index a311be13171..a4847a857b3 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -7384,6 +7384,16 @@ count_reg_usage (rtx x, int *counts, rtx dest, int incr) count_reg_usage (XEXP (x, 1), counts, NULL_RTX, incr); return; + case ASM_OPERANDS: + /* If the asm is volatile, then this insn cannot be deleted, + and so the inputs *must* be live. */ + if (MEM_VOLATILE_P (x)) + dest = NULL_RTX; + /* Iterate over just the inputs, not the constraints as well. */ + for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--) + count_reg_usage (ASM_OPERANDS_INPUT (x, i), counts, dest, incr); + return; + case INSN_LIST: abort (); diff --git a/gcc/testsuite/gcc.dg/asm-8.c b/gcc/testsuite/gcc.dg/asm-8.c new file mode 100644 index 00000000000..a3f3962eb16 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-8.c @@ -0,0 +1,9 @@ +/* PR inline-asm/11676 */ +/* { dg-do compile } */ +/* { dg-options "-O -Wall" } */ + +void foo(void) +{ + long x = 0; + asm volatile ("" : "=r"(x) : "r"(x)); /* { dg-bogus "uninitialized" } */ +} diff --git a/gcc/testsuite/gcc.dg/i386-asm-1.c b/gcc/testsuite/gcc.dg/i386-asm-1.c new file mode 100644 index 00000000000..aae0de845b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/i386-asm-1.c @@ -0,0 +1,24 @@ +/* PR inline-asm/11676 */ +/* { dg-do run { target i?86-*-* } } */ +/* { dg-options "-O2" } */ + +static int bar(int x) __asm__("bar"); +static int __attribute__((regparm(1), noinline, used)) +bar(int x) +{ + if (x != 0) + abort (); +} + +static int __attribute__((regparm(1), noinline)) +foo(int x) +{ + x = 0; + __asm__ __volatile__("call bar" : "=a"(x) : "a"(x)); +} + +int main() +{ + foo(1); + return 0; +}