On Tue, May 12, 2026 at 2:54 PM Uros Bizjak <[email protected]> wrote:
>
> On Tue, May 12, 2026 at 2:30 PM H.J. Lu <[email protected]> wrote:
> >
> > I am testing this patch.  OK for master if there are no regressions?
> >
> >
> > --
> > H.J.
> > In 64-bit mode, in preserve_none functions, we can use any register for
> > DRAP, except for R12, R13, R14, R15, DI, SI (which are used for parameter
> > passing), SP and BP.  Use R11 instead.  Since no-callee-saved functions
> > don't use R10 nor R13 for parameter passing, they are OK for DRAP.  In
> > 32-bit mode, since preserve_none functions don't change parameter passing,
> > the existing choice is OK.

Please write the above:

"In 64-bit mode, for preserve_none functions, DRAP may use any
register except R12–R15, DI, SI (argument registers), SP, and BP. Use
R11. In non-callee-saved functions R10 and R13 are also available
since they are not used for parameter passing. In 32-bit mode,
preserve_none does not affect parameter passing, so the current
approach remains valid."

> > DRAP register is used to restore stack pointer in epilogue for stack
> > realignment.  Always save and restore DRAP register between prologue
> > and epilogue so that stack pointer can be restored.
> >
> > Tested with CPython 3.14.4 on Linux/x86-64.
> >
> > gcc/
> >
> > PR target/120870
> > * config/i386/i386.cc (ix86_save_reg): Return true for DRAP
> > register.
> > (find_drap_reg): Use R11_REG in preserve_none functions in
> > 64-bit mode.
> >
> > gcc/testsuite/
> >
> > PR target/120870
> > * gcc.target/i386/pr120870-1.c: New test.
> > * gcc.target/i386/pr120870-2.c: Likewise.
> >
> > Signed-off-by: H.J. Lu <[email protected]>
> > Co-Authored-By: Uros Bizjak <[email protected]>
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 9aecd51119f..46bef11d3f8 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -6776,6 +6776,13 @@ ix86_save_reg (unsigned int regno, bool
> maybe_eh_return, bool ignore_outlined)
>  {
>    rtx reg;
>
> +  /* Save and restore DRAP register between prologue and epilogue so
> +     that stack pointer can be restored.  */
> +  if (crtl->drap_reg
> +      && regno == REGNO (crtl->drap_reg)
> +      && !cfun->machine->no_drap_save_restore)
> +    return true;
> +
>
> Please remove a copy of this code later in the ix86_save_reg function.
> It is a dead code now.

+      /* In preserve_none functions, we can use any register for DRAP,
+     except for R12_REG, R13_REG, R14_REG, R15_REG, DI_REG, SI_REG
+     (which are used for parameter passing), SP_REG and BP_REG.
+     Pick R11_REG instead.  Since no-callee-saved functions don't
+     use R10_REG nor R13_REG for parameter passing, they are OK
+     for DRAP.  */


Also, please rewrite this part similar to the commit message.

Uros.

Reply via email to