RISC-V: Avoid unused frame-pointer references in stack ties

Epilogue stack ties referenced s0 without a frame pointer, making the
unsaved register ever live.  Regrename could then select it and
corrupt callee-saved state during exception unwinding.

The simpler fix of allowing equal operands in the existing pattern is
unsafe: copy propagation can fold stack_tie (sp, t3) used by stack
probing into stack_tie (sp, sp).  This removes t3 = sp while CFI
still names t3 as the CFA.

Keep the two-register pattern distinct and add an SP-only form for
epilogue barriers.

gcc/ChangeLog:

	* config/riscv/riscv-sr.cc (riscv_sr_match_epilogue): Accept
	SP-only stack ties.
	* config/riscv/riscv.cc (riscv_emit_stack_tie): Use parameterized
	generators and emit SP-only ties.
	(riscv_expand_epilogue): Use SP ties without a frame pointer.
	* config/riscv/riscv.md (@stack_tie<mode>): Use a parameterized name.
	(@stack_tie_sp<mode>): New pattern.

gcc/testsuite/ChangeLog:

	* g++.target/riscv/stack-tie-unwind.C: New test.
	* gcc.target/riscv/stack-tie-no-fp.c: New test.

Signed-off-by: Jin Ma <jinma@linux.alibaba.com>
5 files changed