qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tcg: `reachable_code_pass()` remove empty else-branch


From: Anton Johansson
Subject: Re: [PATCH] tcg: `reachable_code_pass()` remove empty else-branch
Date: Fri, 3 Mar 2023 15:31:44 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.0


On 3/1/23 23:37, Taylor Simpson wrote:
diff --git a/tcg/tcg.c b/tcg/tcg.c
index a4a3da6804..531bc74231 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2664,21 +2664,40 @@ static void reachable_code_pass(TCGContext *s)
                  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);
Can't we just insert a while loop here to move op_prev back across labels?

     while (op_next->opc == INDEX_op_set_label) {
         op_prev = QTAILQ_PREV(op, op_prev);
     }

-                    if (op_prev->opc == INDEX_op_br &&
-                        label == arg_label(op_prev->args[0])) {
Ah I see, you're thinking something like

    dead = false;
    remove = false;

    if (label->refs == 1) {
        TCGOp *op_prev = NULL;
        do {
            op_prev = QTAILQ_PREV(op_prev, link);
        } while (op_prev->opc == INDEX_op_set_label);

        if (op_prev->opc == INDEX_op_br &&
            label == arg_label(op_prev->args[0])) {
            tcg_op_remove(s, op_prev);
            remove = true;
        }
    }

to handle

    br
    set_label
    ...
    set_label

I do like being able to combine both branches, and we're no longer relying on the next iteration of the loop to clean up the final set_label. Since we won't
ever encounter more than one intermediate set_label this might be overkill,
but either way I think it's an improvement.

Thanks for the feedback, I'll resubmit with this change! :)

--
Anton Johansson,
rev.ng Labs Srl.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]