On 6/20/23 14:49, Richard Sandiford via Gcc-patches wrote:
The SVE handling of stack clash protection copied the stack
pointer to X11 before the probe and set up X11 as the CFA
for unwind purposes:

     /* This is done to provide unwinding information for the stack
        adjustments we're about to do, however to prevent the optimizers
        from removing the R11 move and leaving the CFA note (which would be
        very wrong) we tie the old and new stack pointer together.
        The tie will expand to nothing but the optimizers will not touch
        the instruction.  */
     rtx stack_ptr_copy = gen_rtx_REG (Pmode, STACK_CLASH_SVE_CFA_REGNUM);
     emit_move_insn (stack_ptr_copy, stack_pointer_rtx);
     emit_insn (gen_stack_tie (stack_ptr_copy, stack_pointer_rtx));

     /* We want the CFA independent of the stack pointer for the
        duration of the loop.  */
     add_reg_note (insn, REG_CFA_DEF_CFA, stack_ptr_copy);
     RTX_FRAME_RELATED_P (insn) = 1;

-fcprop-registers is now smart enough to realise that X11 = SP,
replace X11 with SP in the stack tie, and delete the instruction
created above.

This patch tries to prevent that by making stack_tie fussy about
the register numbers.  It fixes failures in
gcc.target/aarch64/sve/pcs/stack_clash*.c.

Tested on aarch64-linux-gnu & pushed.
Thanks for taking care of this. It was a bit surprising that we ran into these problems given that we were allowing regcprop to propagate sp->gpr copies a few years back and we're just re-enabling that capability in the safe cases. Presumably this stack tie went in after we'd disabled propagating away sp->gpr copies.

Jeff

Reply via email to