This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: basic asm and memory clobbers
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: David Wohlferd <dw at LimeGreenSocks dot com>
- Cc: Paul_Koning at Dell dot com, law at redhat dot com, aph at redhat dot com, rth at redhat dot com, jakub at redhat dot com, gcc at gcc dot gnu dot org, rth at gcc dot gnu dot org, pinskia at gcc dot gnu dot org, sandra at codesourcery dot com
- Date: Mon, 23 Nov 2015 20:22:17 -0600
- Subject: Re: basic asm and memory clobbers
- Authentication-results: sourceware.org; auth=none
- References: <564F3C6E dot 5010908 at redhat dot com> <20151120153431 dot GJ5675 at tucnak dot redhat dot com> <564F46CF dot 2030403 at redhat dot com> <564FB2ED dot 70803 at LimeGreenSocks dot com> <56506A03 dot 7030609 at LimeGreenSocks dot com> <5652E4A6 dot 9090905 at redhat dot com> <56537921 dot 9070809 at redhat dot com> <565386CA dot 8080005 at LimeGreenSocks dot com> <C080D84D-C192-46F6-BAE9-9E3B5A9F766C at dell dot com> <5653BFC5 dot 5080305 at LimeGreenSocks dot com>
On Mon, Nov 23, 2015 at 05:39:17PM -0800, David Wohlferd wrote:
> On 11/23/2015 1:44 PM, Paul_Koning@Dell.com wrote:
> >>On Nov 23, 2015, at 4:36 PM, David Wohlferd <dw@LimeGreenSocks.com> wrote:
> >>
> >>...
> >>>The more I think about it, I'm just not keen on forcing all those
> >>>old-style asms to change.
> >>If you mean you aren't keen to change them to "clobber all," I'm with
> >>you. If you are worried about changing them from basic to extended, what
> >>kinds of problems do you foresee? I've been reading a lot of basic asm
> >>lately, and it seems to me that most of it would be fine with a simple
> >>colon. Certainly no worse than the current behavior.
> >I'm not sure. I have some asm("sync") which I think assume that this
> >means asm("sync"::"memory")
>
> Another excellent reason to nudge people towards using extended asm. If
> you saw asm("sync":::"memory"), you would *know* what it did, without
> having to read the docs (which don't say anyway).
>
> I'm pretty confident that asm("") doesn't clobber memory on i386, but
> maybe that behavior is platform-specific. Since i386 doesn't have
> "sync", I assume you are on something else?
>
> If you have a chance to experiment, I'd love confirmation from other
> platforms that asm("blah") is the same as asm("blah":). Feel free to
> email me off list to discuss.
The extended asm one is "asm_operands", the basic asm one is "asm_input".
There are places where those are handled differently. If any of that
matters, who knows.
Here is a test that shows that on at least PowerPC the basic asm is
identical to the extended asm without clobber (compile with -O2 -S and
-fno-ipa-icf if you want to have it easier to read). In this case,
the basic asm is treated as not clobbering memory at the tree level
already, before expanding to RTL.
Segher
===
int a;
void ext_m(void)
{
int t = a;
a = 42;
asm("lolz" : : : "memory");
a = t;
}
void ext(void)
{
int t = a;
a = 42;
asm("lolz" :);
a = t;
}
void bas(void)
{
int t = a;
a = 42;
asm("lolz");
a = t;
}
===
PowerPC output (-m32, redacted):
ext_m:
lis 9,a@ha
li 8,42
lwz 10,a@l(9)
stw 8,a@l(9)
lolz
stw 10,a@l(9)
blr
ext:
lolz
blr
bas:
lolz
blr