This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Don't use auto inc/dec addresses in asm operands


On Fri, Jul 10, 2009 at 12:54 PM, Richard
Sandiford<richards@transitive.com> wrote:
> This patch fixes a case in which an AIX compiler would use a
> PRE_INC address inside an asm "m" operand. ?We can't rely on
> asm operands to do increments and decrements like this,
> because the asm can legitimately write to the memory more
> than once or (as here) not write to it at all.
>
> Tested on powerpc-ibm-aix6.1. ?OK to install?

Ok.

We should be able to count the number of uses of operands - but
that of course would work only if every instruction is executed only
once.

Thanks,
Richard.

> Richard
>
>
> gcc/
> ? ? ? ?* auto-inc-dec.c (merge_in_block): Don't consider modifying
> ? ? ? ?asm "m" operands.
>
> Index: gcc/auto-inc-dec.c
> ===================================================================
> --- gcc/auto-inc-dec.c ?2009-07-01 09:02:47.000000000 +0100
> +++ gcc/auto-inc-dec.c ?2009-07-09 10:17:43.000000000 +0100
> @@ -1404,7 +1404,9 @@ merge_in_block (int max_reg, basic_block
> ? ? ? ? ? ? ? ?}
> ? ? ? ? ? ?}
> ? ? ? ?}
> - ? ? ?else
> + ? ? ?/* We can't add pre- and post-modifications to asms, because we don't
> + ? ? ? ?know how many times the asm will access its memory operands. ?*/
> + ? ? ?else if (asm_noperands (PATTERN (insn)) < 0)
> ? ? ? ?{
> ? ? ? ? ?insn_is_add_or_inc = false;
> ? ? ? ? ?mem_insn.insn = insn;
> Index: gcc/testsuite/gcc.c-torture/execute/autoinc-1.c
> ===================================================================
> --- /dev/null ? 2009-07-01 13:46:58.466210000 +0100
> +++ gcc/testsuite/gcc.c-torture/execute/autoinc-1.c ? ? 2009-07-09 10:02:49.000000000 +0100
> @@ -0,0 +1,29 @@
> +static inline void __attribute__((always_inline))
> +f1 (void)
> +{
> + ?long unused;
> + ?asm volatile ("nop" : "=m" (unused) :: "memory");
> +}
> +
> +static void __attribute__((noinline))
> +f2 (long *val)
> +{
> + ?*val = 0x1234;
> +}
> +
> +static long __attribute__((noinline))
> +test (void)
> +{
> + ?f1 ();
> + ?{
> + ? ?long val;
> + ? ?f2 (&val);
> + ? ?return val;
> + ?}
> +}
> +
> +int
> +main (void)
> +{
> + ?return test () != 0x1234;
> +}
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]