https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120870
--- Comment #61 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Uroš Bizjak from comment #60)
> (In reply to H.J. Lu from comment #59)
> > > HJ, do we also need to check TYPE_NO_CALLER_SAVED_REGISTERS here?
> >
> > No. TYPE_NO_CALLER_SAVED_REGISTERS is OK since callee will preserve
> > everything.
>
> The save of DRAP register is *inside* the realigned frame and is later used
> to restore RSP. Without saved DRAP, it can be clobbered in the function and
> RSP will be restored with clobbered value.
It is covered by
@@ -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;
+