On Wed, Apr 23, 2025 at 04:46:17PM +0200, Jakub Jelinek wrote:
[...]
> > > It won't really work at -O0 but should work for -O1 and above, at least 
> > > when
> > > one doesn't really try to modify the parameter conditionally and hope it 
> > > will
> > > be optimized away in the end.
> > 
> > It also fails for
> > 
> > extern int bar (int p1, int p2, int p3, int p4, int p5);
> > int foo (int p1, int p2, int p3, int p4, int p5)
> > {
> >   [[gnu::musttail]] return bar (p1, p2, p3, p4, p5);
> > }
> > 
> > since rtx_equal_p (parm, parm_rtx) does not hold for p5
> > 
> > (gdb) call debug_rtx(parm_rtx)
> > (reg:SI 6 %r6)
> > (gdb) call debug_rtx(parm)
> > (reg:DI 6 %r6 [ p5+-4 ])
> > 
> > due to a missmatch between extended and non-extended values.  Maybe a
> > check like
> > 
> > REGNO (parm) == REGNO (parm_rtx)
> > && REG_NREGS (parm) == REG_NREGS (parm_rtx)
> > 
> > is sufficient?
> 
> I think it depends the details of the ABI.
> I believe when the argument is SSA_NAME (D) of a PARM_DECL it means
> the parameter and the argument have (GIMPLE) compatible types.
> Are the upper 32 bits always sign extended (or zero extended, or
> sign vs. zero extended depending on if it is signed or unsigned < 64bit
> type)?

Yes, every parameter is sign or zero extended if its type is smaller
than 64bit.

> If it must be extended, then yes, testing REGNO and REG_NREGS might be
> enough, if the upper bits are unspecified, I'd worry we could sometimes
> try to change those bits and break the caller that way.
> If {un,}signed {char,short,int} are always zero/sign extended to 64-bit,
> what about BITINT_TYPEs?

The _BitInt ABI isn't fixed yet, however, we plan to zero/sign extend
excess bits.  In particular for _BitInt(N) with N <= 64, the argument is
sign/zero extended to a 64bit value, if passed via a register.

> Another question is if it shouldn't be handled in the PARALLEL case as well
> (e.g. if some -m32 long long parameter could be partly passed in %r6 and
> partly on the stack).

Yea, that is something I still try to figure out.  The PARALLEL handling
was introduced by r0-99328-g9602b6a1b8de60.  I guess a PARALLEL is used
exclusively in case a register pair is required.  Though, I'm not sure
whether this is correct or not.  There doesn't seem to exist a test for
this.  I will look into this.

Note, on s390 a parameter is either passed in a register (pair) or via
memory, but not partly in a register and memory.

Cheers,
Stefan

Reply via email to