[gcc(refs/vendors/ARM/heads/arm-perf-staging)] x86: Restore the frame pointer in word_mode

Tamar Christina tnfchris@gcc.gnu.org
Fri Jul 17 14:35:02 GMT 2020


https://gcc.gnu.org/g:efc1f3577f38bb213b313661c025ac965baee953

commit efc1f3577f38bb213b313661c025ac965baee953
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Apr 13 04:23:05 2020 -0700

    x86: Restore the frame pointer in word_mode
    
    We must restore the frame pointer in word_mode for eh_return epilogues
    since the upper 32 bits of RBP register can have any values.
    
    Tested on Linux/x32 and Linux/x86-64.
    
            PR target/94556
            * config/i386/i386.c (ix86_expand_epilogue): Restore the frame
            pointer in word_mode for eh_return epilogues.

Diff:
---
 gcc/ChangeLog          |  6 ++++++
 gcc/config/i386/i386.c | 11 ++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8bfc2127989..b4229419bc2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR target/94556
+	* config/i386/i386.c (ix86_expand_epilogue): Restore the frame
+	pointer in word_mode for eh_return epilogues.
+
 2020-04-13  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
 	* config/msp430/msp430.c (msp430_print_operand): Don't add offsets to
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index ca3b7dc06c2..5e87cd463d0 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -9052,8 +9052,13 @@ ix86_expand_epilogue (int style)
 	      t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
 	      emit_insn (gen_rtx_SET (sa, t));
 
-	      t = gen_frame_mem (Pmode, hard_frame_pointer_rtx);
-	      insn = emit_move_insn (hard_frame_pointer_rtx, t);
+	      /* NB: eh_return epilogues must restore the frame pointer
+		 in word_mode since the upper 32 bits of RBP register
+		 can have any values.  */
+	      t = gen_frame_mem (word_mode, hard_frame_pointer_rtx);
+	      rtx frame_reg = gen_rtx_REG (word_mode,
+					   HARD_FRAME_POINTER_REGNUM);
+	      insn = emit_move_insn (frame_reg, t);
 
 	      /* Note that we use SA as a temporary CFA, as the return
 		 address is at the proper place relative to it.  We
@@ -9068,7 +9073,7 @@ ix86_expand_epilogue (int style)
 	      add_reg_note (insn, REG_CFA_DEF_CFA,
 			    plus_constant (Pmode, sa, UNITS_PER_WORD));
 	      ix86_add_queued_cfa_restore_notes (insn);
-	      add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx);
+	      add_reg_note (insn, REG_CFA_RESTORE, frame_reg);
 	      RTX_FRAME_RELATED_P (insn) = 1;
 
 	      m->fs.cfa_reg = sa;


More information about the Gcc-cvs mailing list