https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120870
--- Comment #52 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Uroš Bizjak from comment #51)
> Prototype patch to confirm Comment #48:
>
> --cut here--
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index e73c2d7f7d0..db571853103 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -496,6 +496,10 @@ ix86_profile_before_prologue (void)
> return flag_fentry != 0;
> }
>
> +/* In no-callee-saved and preserve_none functions,
> + reserve BX_REG for DRAP register. */
> +#define X86_NO_CALLEE_DRAP_REG BX_REG
> +
> /* Update register usage after having seen the compiler flags. */
>
> static void
> @@ -6807,7 +6811,8 @@ ix86_save_reg (unsigned int regno, bool
> maybe_eh_return, bool ignore_outlined)
>
> case TYPE_NO_CALLEE_SAVED_REGISTERS:
> case TYPE_PRESERVE_NONE:
> - if (regno != HARD_FRAME_POINTER_REGNUM)
> + if (regno != HARD_FRAME_POINTER_REGNUM
> + && regno != X86_NO_CALLEE_DRAP_REG)
> return false;
> break;
> }
> @@ -7940,6 +7945,11 @@ pro_epilogue_adjust_stack (rtx dest, rtx src, rtx
> offset,
> static unsigned int
> find_drap_reg (void)
> {
> + if (cfun->machine->call_saved_registers == TYPE_PRESERVE_NONE
> + || (cfun->machine->call_saved_registers
> + == TYPE_NO_CALLEE_SAVED_REGISTERS))
> + return X86_NO_CALLEE_DRAP_REG;
> +
> tree decl = cfun->decl;
>
> /* Always use callee-saved register if there are no caller-saved
> --cut here--
Yes, it works on the testcase.