Hi!

On Thu, Nov 15, 2018 at 03:54:03PM +0000, Michael Matz wrote:
> On Wed, 14 Nov 2018, Alexander Monakov wrote:
> > On Wed, 14 Nov 2018, Segher Boessenkool wrote:
> > > Yeah, using local register vars to access global registers only works
> > > by accident.  It does work currently though, and people apparently use
> > > it, so we shouldn't break it :-/
> > 
> > In the proposed approach (copying from/to pseudos just before/after the
> > asm) we can emulate historic behavior by making uninitialized pseudos
> > take values of the corresponding hardregs. If we decide that doing that
> > just for must-uninit pseudos is enough, it's a simple extension to the
> > existing init-regs pass.  Does this sound reasonable?
> 
> Or we can just decide that nothing needs fixing.  In particular about this 
> from Jakub and Segher:
> 
> > > What doesn't work as the reporter expect is assumption that local hard
> > > register variables that live across function calls must have their 
> > > values preserved; they can be modified by the callees.
> > 
> > It would be really nice if we could fix that :-)
> 
> I disagree that there's something to fix.

What I would like fixed is the surprising behaviour that people run into
time after time again.

> My mental model for local reg 
> vars has always been that such vars are actually an alias for that 
> register, not comparable to normal automatic variables (so, much like 
> global reg vars, except that they don't reserve away the register from 
> regalloc).

That was the case long ago, yes.  And mostly it still is, but this is not
guaranteed behaviour.  Things are expanded as being in that reg, but many
optimisations can destroy this later.  And function calls (some of which
are not explicit in the user's program!) will clobber things.  And and and.
It is very hard to use this feature reliably.

> I.e. like volatile they can arbitrarily change their value.  
> I don't know if other peoples mind model is similar, but it certainly is 
> the model that is implemented in the GIMPLE pipeline (and if memory serves 
> well of the RTL pipeline as well).
> 
> Copying outof/into pseudos around asms serves no purpose with that model, 
> it rather makes regvars somewhat "safer" to use, without actually making 
> them safer (there _is_ nothing safe about them).

The only supported case is for inputs and outputs to extended asm.  Maybe
we should just come up with a syntax so you can specify hard regs for that
directly (without needing a separate regclass for every reg).


Segher

Reply via email to