On Wed, Nov 14, 2018 at 03:33:43PM +0300, Alexander Monakov wrote:
> On Wed, 14 Nov 2018, Jakub Jelinek wrote:
> 
> > On Wed, Nov 14, 2018 at 06:22:51AM -0600, Segher Boessenkool wrote:
> > > Btw, if you just add
> > > 
> > > void *
> > > retsp (void)
> > > {
> > >   register void *sp __asm ("sp");
> > >   asm ("" : "+g" (sp));  // <-- this line
> > >   return sp;
> > > }
> > > 
> > > everything works fine.
> > 
> > Even in what you are proposing, i.e. handle the var as any other var
> > in SSA form and only copy into the hard register right before asm and out of
> > it after it?
> > Because 
> > {
> >   void *sp;
> >   asm ("" : "+g" (sp));
> >   return sp;
> > }
> > would store into the register default definition of the SSA_NAME (the var
> > has no initializer).
> 
> I think with "=g" rather than "+g" this example is ok.

No, it needs the register var as an input.  That is the whole *point*.
It could output elsewhere, like with

void *
retsp (void)
{
  register void *sp __asm ("sp");
  void *p;
  asm ("" : "=g" (p) : "0" (sp));
  return p;
}

(which also works reliably with current GCC).

Or like

void *
retsp (void)
{
  register void *sp __asm ("sp");
  void *p;
  asm ("mov %0,%1" : "=r" (p) : "r" (sp));
  return p;
}

if you don't want to tie the asm input and output (but use an extra
machine instruction, alas).


Segher

Reply via email to