[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 35/62] tcg: Remove branch-to-next regardless of reference count
From: |
Richard Henderson |
Subject: |
[PULL 35/62] tcg: Remove branch-to-next regardless of reference count |
Date: |
Tue, 28 Feb 2023 16:56:16 -1000 |
Just because the label reference count is more than 1 does
not mean we cannot remove a branch-to-next. By doing this
first, the label reference count may drop to 0, and then
the label itself gets removed as before.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 855e4cc537..9739e4830f 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2637,7 +2637,7 @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op,
/* Reachable analysis : remove unreachable code. */
static void reachable_code_pass(TCGContext *s)
{
- TCGOp *op, *op_next;
+ TCGOp *op, *op_next, *op_prev;
bool dead = false;
QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) {
@@ -2647,6 +2647,22 @@ static void reachable_code_pass(TCGContext *s)
switch (op->opc) {
case INDEX_op_set_label:
label = arg_label(op->args[0]);
+
+ /*
+ * Optimization can fold conditional branches to unconditional.
+ * If we find a label which is preceded by an unconditional
+ * branch to next, remove the branch. We couldn't do this when
+ * processing the branch because any dead code between the branch
+ * and label had not yet been removed.
+ */
+ op_prev = QTAILQ_PREV(op, link);
+ if (op_prev->opc == INDEX_op_br &&
+ label == arg_label(op_prev->args[0])) {
+ tcg_op_remove(s, op_prev);
+ /* Fall through means insns become live again. */
+ dead = false;
+ }
+
if (label->refs == 0) {
/*
* While there is an occasional backward branch, virtually
@@ -2660,21 +2676,6 @@ static void reachable_code_pass(TCGContext *s)
/* Once we see a label, insns become live again. */
dead = false;
remove = false;
-
- /*
- * Optimization can fold conditional branches to unconditional.
- * If we find a label with one reference which is preceded by
- * an unconditional branch to it, remove both. This needed to
- * wait until the dead code in between them was removed.
- */
- if (label->refs == 1) {
- TCGOp *op_prev = QTAILQ_PREV(op, link);
- if (op_prev->opc == INDEX_op_br &&
- label == arg_label(op_prev->args[0])) {
- tcg_op_remove(s, op_prev);
- remove = true;
- }
- }
}
break;
--
2.34.1
- [PULL 23/62] target/mips: Replace `tb_pc()` with `tb->pc`, (continued)
- [PULL 23/62] target/mips: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 24/62] target/microblaze: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 28/62] target/hexagon: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 30/62] target/arm: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 32/62] tcg: Adjust TCGContext.temps_in_use check, Richard Henderson, 2023/02/28
- [PULL 25/62] target/loongarch: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 31/62] include/exec: Remove `tb_pc()`, Richard Henderson, 2023/02/28
- [PULL 33/62] accel/tcg: Pass max_insn to gen_intermediate_code by pointer, Richard Henderson, 2023/02/28
- [PULL 29/62] target/avr: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 34/62] accel/tcg: Use more accurate max_insns for tb_overflow, Richard Henderson, 2023/02/28
- [PULL 35/62] tcg: Remove branch-to-next regardless of reference count,
Richard Henderson <=
- [PULL 26/62] target/i386: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 27/62] target/hppa: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 36/62] tcg: Rename TEMP_LOCAL to TEMP_TB, Richard Henderson, 2023/02/28
- [PULL 37/62] tcg: Use noinline for major tcg_gen_code subroutines, Richard Henderson, 2023/02/28
- [PULL 38/62] tcg: Add liveness_pass_0, Richard Henderson, 2023/02/28
- [PULL 39/62] tcg: Remove TEMP_NORMAL, Richard Henderson, 2023/02/28
- [PULL 47/62] accel/tcg/plugin: Tidy plugin_gen_disable_mem_helpers, Richard Henderson, 2023/02/28
- [PULL 58/62] target/ppc: Don't use tcg_temp_local_new, Richard Henderson, 2023/02/28
- [PULL 46/62] accel/tcg/plugin: Use tcg_temp_ebb_*, Richard Henderson, 2023/02/28
- [PULL 55/62] target/hppa: Don't use tcg_temp_local_new, Richard Henderson, 2023/02/28