This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Reenable CSE of non-volatile inline asm (PR rtl-optimization/63637)
- From: Jeff Law <law at redhat dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Richard Biener <rguenther at suse dot de>, Eric Botcazou <ebotcazou at adacore dot com>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 14 Jan 2015 22:06:33 -0700
- Subject: Re: [PATCH] Reenable CSE of non-volatile inline asm (PR rtl-optimization/63637)
- Authentication-results: sourceware.org; auth=none
- References: <20150113161819 dot GD1405 at tucnak dot redhat dot com> <20150113163840 dot GA4183 at gate dot crashing dot org> <54B575D7 dot 8030107 at redhat dot com> <20150113201322 dot GJ1405 at tucnak dot redhat dot com> <54B59964 dot 7070707 at redhat dot com> <20150114000315 dot GA32710 at gate dot crashing dot org> <54B609A9 dot 9090800 at redhat dot com> <20150114151906 dot GA21784 at gate dot crashing dot org>
On 01/14/15 08:19, Segher Boessenkool wrote:
"
@findex clobber
@item (clobber @var{x})
Represents the storing or possible storing of an unpredictable,
undescribed value into @var{x}, which must be a @code{reg},
@code{scratch}, @code{parallel} or @code{mem} expression.
[...]
If @var{x} is @code{(mem:BLK (const_int 0))} or
@code{(mem:BLK (scratch))}, it means that all memory
locations must be presumed clobbered.
"
Note it doesn't mention reading memory.
The documentation is incomplete. The right thing to do is fix the
documentation and treat the "memory" tag appearing in the "clobber"
section as a read as well as a write.
It's lame, but the historical decision by RMS to put that tag into the
clobbers section is what it is. Don't get too hung up on it. RMS just
botched it.
Now if we go back to my earlier quote:
"
If your assembler instructions access memory in an unpredictable
fashion, add @samp{memory} to the list of clobbered registers.
Note "access" not "write".
This
causes GCC to not keep memory values cached in registers across the
assembler instruction and not optimize stores or loads to that memory.
You also should add the @code{volatile} keyword if the memory
affected is not listed in the inputs or outputs of the @code{asm}, as
the @samp{memory} clobber does not count as a side-effect of the
@code{asm}.
"
That last line means the compiler is free to delete a non-volatile
asm with a memory clobber if that asm is not needed for dataflow. Or
that is how I read it; it is trying to indicate that if you want to
prevent the memory clobber from being deleted (together with the rest
of the asm), you need to make the asm volatile.
So as far as I can see the compiler can CSE two identical non-volatile
asms with memory clobber just fine. Older GCC (I tried 4.7.2) does do
this; current mainline doesn't. I think it should.
No, it should not CSE those two cases. That's simply wrong and if an
older version did that optimization, that's a bug.
jeff