This is the mail archive of the
mailing list for the GCC project.
Re: Can shrink-wrapping ever move prologue past an ASM statement?
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jeff Law <law at redhat dot com>
- Cc: Josh Poimboeuf <jpoimboe at redhat dot com>, GCC Mailing List <gcc at gcc dot gnu dot org>, Vojtech Pavlik <vojtech at suse dot cz>
- Date: Wed, 8 Jul 2015 16:38:23 -0500
- Subject: Re: Can shrink-wrapping ever move prologue past an ASM statement?
- Authentication-results: sourceware.org; auth=none
- References: <20150707175349 dot GA2325 at virgil dot suse dot cz> <20150707184415 dot GB13004 at gate dot crashing dot org> <20150708092309 dot GB2325 at virgil dot suse dot cz> <20150708103631 dot GA23975 at gate dot crashing dot org> <20150708162234 dot GB4687 at treble dot redhat dot com> <20150708205111 dot GD4687 at treble dot redhat dot com> <559D92E0 dot 6030008 at redhat dot com>
On Wed, Jul 08, 2015 at 03:15:12PM -0600, Jeff Law wrote:
> >>>>>For other archs, e.g. x86-64, you can do
> >>>>> register void *sp asm("%sp");
> >>>>> asm volatile("call func" : "+r"(sp));
> >I've found that putting "sp" in the clobber list also seems to work:
> > asm volatile("call func" : : : "sp");
> >This syntax is nicer because it doesn't need a local variable associated
> >with the register. Do you see any issues with this approach?
> Given that SP isn't subject to register allocation, I'd expect it's
> fine. Note that some folks have (loudly) requested that GCC issue an
> error if an asm tries to clobber sp.
> The call doesn't actually clobber the stack pointer does it? ISTM that
> a use of sp makes more sense and is better "future proof'd" than
> clobbering sp.
LRA thinks that when an asm clobbers sp, it can no longer eliminate to sp.
When an asm "merely" writes to sp, it is fine with that.
In both cases everything happily pretends sp does not actually change.
So it is a good thing that in fact it doesn't ;-)
All these approaches assume the only thing you really want to happen
before the asm call is the sp changes done in the prologue; if the
prologue does other things you depend on (setting up fp?), if you want
futureproofitivity, you want to make the asm depend on that as well.