[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH] tcg: `reachable_code_pass()` remove empty else-branch
From: |
Taylor Simpson |
Subject: |
RE: [PATCH] tcg: `reachable_code_pass()` remove empty else-branch |
Date: |
Wed, 1 Mar 2023 22:37:51 +0000 |
> -----Original Message-----
> From: Anton Johansson <anjo@rev.ng>
> Sent: Wednesday, March 1, 2023 7:22 AM
> To: qemu-devel@nongnu.org
> Cc: ale@rev.ng; richard.henderson@linaro.org; Taylor Simpson
> <tsimpson@quicinc.com>
> Subject: [PATCH] tcg: `reachable_code_pass()` remove empty else-branch
>
> This patch extends reachable_code_pass() to also deal with empty else-
> branches of the form
>
> br $L0
> set_label $L1
> set_label $L0
>
> converting them to
>
> set_label $L1
>
> when $L0 is only referenced by the br op. This type of empty-else branch will
> be emitted by idef-parser in the Hexagon frontend once CANCEL statements
> have been ignored.
>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
> tcg/tcg.c | 41 ++++++++++++++++++++++++++++++-----------
> 1 file changed, 30 insertions(+), 11 deletions(-)
>
> 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])) {
Also, here is the patch that exposes the need for this optimization
https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg07236.html
Thanks,
Taylor