This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: altivec trashing frame ptr reg


On Thu, Feb 28, 2002 at 05:15:33PM +1100, Aldy Hernandez wrote:
> >>>For ABI_V4, r12 may be in use as a frame pointer.
> >>>	* config/rs6000/rs6000.c (rs6000_emit_prologue <vrsave>): Don't
> >>>	zap the temp frame pointer reg.
> >>
> >>Are you sure r0 is available?
> >
> >Looks like it is to me..  I'll admit to not knowing for sure that
> >"mtvrsave 0" is valid.
> 
> actually i was debugging code today that used r0 to hold the link
> register, right before it placed it on the stack (in the prologue).
> 
> so i don't think this patch is correct.

The prologue is scheduled, so instructions can move around a bit.  The
r0 use you're talking about is initially generated just after the
vrsave code.

> besides, the rest of the pro/epilogue code uses r12 (david
> suggested i use it).  if you are tripping this with vrsave,
> it just as likely will be tripped with other pro/epilogue code.

The bug is pretty obvious if you'd care to take a look at the code.

      /* Save VRSAVE.  */
      offset = info->vrsave_save_offset + sp_offset;
      mem
	= gen_rtx_MEM (SImode,
		       gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
      set_mem_alias_set (mem, rs6000_sr_alias_set);
      insn = emit_move_insn (mem, reg);

Note that we use frame_reg_rtx.  Further note that frame_reg_rtx may
be set to r12 at the start of rs6000_emit_prologue, here:

  rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
[snip]
  /* For V.4, update stack before we do any saving and set back pointer.  */
  if (info->push_p && DEFAULT_ABI == ABI_V4)
    {
      if (info->total_size < 32767)
	sp_offset = info->total_size;
      else
	frame_reg_rtx = frame_ptr_rtx;

So, ABI_V4, big stack frame, altivec vrsave -> zap random memory, boom.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]