From 3df6fac0080468d1521775e82a5e060f0b1c78ca Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Fri, 6 Nov 2020 14:53:29 -0800 Subject: [PATCH] amdgcn: Fix exec register live-on-entry to BB in md-reorg This patch fixes a corner case in the AMD GCN md-reorg pass when the EXEC register is live on entry to a BB, and could be clobbered by code inserted by the pass before a use in (e.g.) a different BB. 2021-01-13 Julian Brown gcc/ * config/gcn/gcn.c (gcn_md_reorg): Fix case where EXEC reg is live on entry to a BB. --- gcc/config/gcn/gcn.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c index 0fb9bd2..630ce4e 100644 --- a/gcc/config/gcn/gcn.c +++ b/gcc/config/gcn/gcn.c @@ -4501,6 +4501,8 @@ gcn_md_reorg (void) df_insn_rescan_all (); } + df_live_add_problem (); + df_live_set_all_dirty (); df_analyze (); /* This pass ensures that the EXEC register is set correctly, according @@ -4522,6 +4524,17 @@ gcn_md_reorg (void) int64_t curr_exec = 0; /* 0 here means 'the value is that of EXEC after last_exec_def is executed'. */ + bitmap live_in = DF_LR_IN (bb); + bool exec_live_on_entry = false; + if (bitmap_bit_p (live_in, EXEC_LO_REG) + || bitmap_bit_p (live_in, EXEC_HI_REG)) + { + if (dump_file) + fprintf (dump_file, "EXEC reg is live on entry to block %d\n", + (int) bb->index); + exec_live_on_entry = true; + } + FOR_BB_INSNS_SAFE (bb, insn, curr) { if (!NONDEBUG_INSN_P (insn)) @@ -4660,6 +4673,8 @@ gcn_md_reorg (void) exec_lo_def_p == exec_hi_def_p ? "full" : "partial", INSN_UID (insn)); } + + exec_live_on_entry = false; } COPY_REG_SET (&live, DF_LR_OUT (bb)); @@ -4669,7 +4684,7 @@ gcn_md_reorg (void) at the end of the block. */ if ((REGNO_REG_SET_P (&live, EXEC_LO_REG) || REGNO_REG_SET_P (&live, EXEC_HI_REG)) - && (!curr_exec_known || !curr_exec_explicit)) + && (!curr_exec_known || !curr_exec_explicit || exec_live_on_entry)) { rtx_insn *end_insn = BB_END (bb); -- 2.7.4