@@ -7761,52 +7761,6 @@ riscv_adjust_libcall_cfi_epilogue ()
return dwarf;
}
-/* return true if popretz pattern can be matched.
- set (reg 10 a0) (const_int 0)
- use (reg 10 a0)
- NOTE_INSN_EPILOGUE_BEG */
-static rtx_insn *
-riscv_zcmp_can_use_popretz (void)
-{
- rtx_insn *insn = NULL, *use = NULL, *clear = NULL;
-
- /* sequence stack for NOTE_INSN_EPILOGUE_BEG*/
- struct sequence_stack *outer_seq = get_current_sequence ()->next;
- if (!outer_seq)
- return NULL;
- insn = outer_seq->first;
- if (!insn || !NOTE_P (insn) || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG)
- return NULL;
-
- /* sequence stack for the insn before NOTE_INSN_EPILOGUE_BEG*/
- outer_seq = outer_seq->next;
- if (outer_seq)
- insn = outer_seq->last;
-
- /* skip notes */
- while (insn && NOTE_P (insn))
- {
- insn = PREV_INSN (insn);
- }
- use = insn;
-
- /* match use (reg 10 a0) */
- if (use == NULL || !INSN_P (use) || GET_CODE (PATTERN (use)) != USE
- || !REG_P (XEXP (PATTERN (use), 0))
- || REGNO (XEXP (PATTERN (use), 0)) != A0_REGNUM)
- return NULL;
-
- /* match set (reg 10 a0) (const_int 0 [0]) */
- clear = PREV_INSN (use);
- if (clear != NULL && INSN_P (clear) && GET_CODE (PATTERN (clear)) == SET
- && REG_P (SET_DEST (PATTERN (clear)))
- && REGNO (SET_DEST (PATTERN (clear))) == A0_REGNUM
- && SET_SRC (PATTERN (clear)) == const0_rtx)
- return clear;
-
- return NULL;
-}
-
static void
riscv_gen_multi_pop_insn (bool use_multi_pop_normal, unsigned mask,
unsigned multipop_size)
@@ -7817,13 +7771,6 @@ riscv_gen_multi_pop_insn (bool use_multi_pop_normal, unsigned mask,
if (!use_multi_pop_normal)
insn = emit_insn (
riscv_gen_multi_push_pop_insn (POP_IDX, multipop_size, regs_count));
- else if (rtx_insn *clear_a0_insn = riscv_zcmp_can_use_popretz ())
- {
- delete_insn (NEXT_INSN (clear_a0_insn));
- delete_insn (clear_a0_insn);
- insn = emit_jump_insn (
- riscv_gen_multi_push_pop_insn (POPRETZ_IDX, multipop_size, regs_count));
- }
else
insn = emit_jump_insn (
riscv_gen_multi_push_pop_insn (POPRET_IDX, multipop_size, regs_count));
@@ -259,7 +259,8 @@ foo (void)
**test_popretz:
** cm.push {ra}, -16
** call f1
-** cm.popretz {ra}, 16
+** li a0,0
+** cm.popret {ra}, 16
*/
long
test_popretz ()
@@ -259,7 +259,8 @@ foo (void)
**test_popretz:
** cm.push {ra}, -16
** call f1
-** cm.popretz {ra}, 16
+** li a0,0
+** cm.popret {ra}, 16
*/
long
test_popretz ()
Root cause: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b27d323a368033f0b37e93c57a57a35fd9997864 Commit above tries in targetm.gen_epilogue () to detect if there's li a0,0 insn at the end of insn chain, if so, cm.popret is replaced by cm.popretz and li a0,0 insn is deleted. Insertion of the generated epilogue sequence into the insn chain doesn't happen at this moment. If later shrink-wrap decides NOT to insert the epilogue sequence at the end of insn chain, then the li a0,0 insn has already been mistakeny removed. Fix this issue by removing generation of cm.popretz in epilogue, leaving the assignment to a0 and use insn with cm.popret. That's likely going to result in some kind of code size regression, but not a correctness regression. Optimization can be done in future. Signed-off-by: Fei Gao <gaofei@eswincomputing.com> gcc/ChangeLog: PR target/113715 * config/riscv/riscv.cc (riscv_zcmp_can_use_popretz): Removed. (riscv_gen_multi_pop_insn): Remove generation of cm.popretz. gcc/testsuite/ChangeLog: * gcc.target/riscv/rv32e_zcmp.c: Adapt TC. * gcc.target/riscv/rv32i_zcmp.c: Likewise. --- gcc/config/riscv/riscv.cc | 53 --------------------- gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c | 3 +- gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c | 3 +- 3 files changed, 4 insertions(+), 55 deletions(-)