2011-02-11 Richard Sandiford gcc/ * cse.c (count_reg_usage): Check side_effects_p. Remove the separate check for volatile asms. gcc/testsuite/ * gcc.dg/torture/volatile-pic-1.c: New test. === modified file 'gcc/cse.c' --- old/gcc/cse.c 2010-11-26 12:03:32 +0000 +++ new/gcc/cse.c 2011-02-11 09:27:19 +0000 @@ -6634,9 +6634,10 @@ case CALL_INSN: case INSN: case JUMP_INSN: - /* We expect dest to be NULL_RTX here. If the insn may trap, mark - this fact by setting DEST to pc_rtx. */ - if (insn_could_throw_p (x)) + /* We expect dest to be NULL_RTX here. If the insn may trap, + or if it cannot be deleted due to side-effects, mark this fact + by setting DEST to pc_rtx. */ + if (insn_could_throw_p (x) || side_effects_p (PATTERN (x))) dest = pc_rtx; if (code == CALL_INSN) count_reg_usage (CALL_INSN_FUNCTION_USAGE (x), counts, dest, incr); @@ -6676,10 +6677,6 @@ 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); === added file 'gcc/testsuite/gcc.dg/torture/volatile-pic-1.c' --- old/gcc/testsuite/gcc.dg/torture/volatile-pic-1.c 1970-01-01 00:00:00 +0000 +++ new/gcc/testsuite/gcc.dg/torture/volatile-pic-1.c 2011-02-11 09:27:19 +0000 @@ -0,0 +1,20 @@ +/* { dg-do run } */ +/* { dg-require-visibility "" } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-fPIC" } */ + +volatile int x __attribute__((visibility("hidden"))); + +void __attribute__((noinline)) bar (void) +{ +#if defined (__arm__) + asm volatile ("mov r3,%0" :: "r" (0xdeadbeef) : "r3"); +#endif + (void) x; +} + +int main (void) +{ + bar (); + return 0; +}