From patchwork Wed Feb 22 23:26:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655714 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp36535wrb; Wed, 22 Feb 2023 15:29:57 -0800 (PST) X-Google-Smtp-Source: AK7set8J8ZsN3o6hQNfvqe+csppg/DnjPGTb9WphNSiUhvw2otk4VIJu+Avic8wjARF95sZu0kvY X-Received: by 2002:ac8:57d3:0:b0:3b9:bca3:d93d with SMTP id w19-20020ac857d3000000b003b9bca3d93dmr3666989qta.22.1677108597143; Wed, 22 Feb 2023 15:29:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677108597; cv=none; d=google.com; s=arc-20160816; b=UbUMVcci41OHkFzSvI7sh9VSmi5ead4TI1S9cdBcD3csD7eYvzZ1gs15rtvRIfSKWR D6hVA+CdHY6gP6DVaeVgmzw6ud0SbC4iOL93iiSgOcgcQY1xKy+QUVlbhp3IgC0z94/k z+1cl77iTuyOv3I1ljDGBi4zdShcko16hscSNuOeLuVa2tCtbHqoWyYAEswoXZC7OL8D 66yz/n+h5HZUEj/JtBWVAI8OrM1Tvaxrp8yv09e4bw0f9KOM6P/7kndWu91gsJUGlJ/a RNJ0qK0OXTEKj2RRctK0glObKF0Sgubq+8Teg0SXKvRNEJ8oqlKD+8MLIu0EHsdGfKTl 4Kog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=5v/dwvyzqW0LrwkDssVFFMNck7V5COuSNYqzQhD5srA=; b=Sl9/SjFXiwKzMD/a5Uj8GcBJWhCit6AQ1rTyKDSEH30Ud4YqHLbjGaWtcEkEy/HMrc dCZbs0xDHclLTkj71qXoqI0qzqOi1CIKC9MXUIM9yw7F9aEMFqprXtZCYpJo+/I2tYfD EH/Wg6F6WM/7XXW0bKvaekDySSYke3XkdZRqBf7aiJFXCp3nPccjCO0k8j2tV6zUaIZF +FsakyaVLi0LYlm3wQVy6B6xW94zPmwozfhCjMPaaa68gXa2fB9AWjCBrhDYxtAF+Cil ZLPAMsUMwerLp2QWKcWCU6dIVu3xjMu4rZQ+02jUmmMlv7RbvjcqYJubAHh08/0ZrFo6 N/Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IJCLofA0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y12-20020ac85f4c000000b003b1089eccc7si16251487qta.582.2023.02.22.15.29.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Feb 2023 15:29:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IJCLofA0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUyWG-0000ON-Rs; Wed, 22 Feb 2023 18:27:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUyWE-0000NN-Hc for qemu-devel@nongnu.org; Wed, 22 Feb 2023 18:27:26 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUyWC-0005Id-Vb for qemu-devel@nongnu.org; Wed, 22 Feb 2023 18:27:26 -0500 Received: by mail-pj1-x102d.google.com with SMTP id d1-20020a17090a3b0100b00229ca6a4636so10902012pjc.0 for ; Wed, 22 Feb 2023 15:27:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5v/dwvyzqW0LrwkDssVFFMNck7V5COuSNYqzQhD5srA=; b=IJCLofA0xfgefN5Z5D1g+iH6fJsUKeTYfxRYg3z1I+qGzLZAnu2UALo3d/D+Zq8ao9 QoXFDgJhHOPa2cpQcI4/cFxYnVBQb3Ix6XVMewK/SbebivAniTLbQM/WHRN1Mbxs3x9y lwPcjAD24CxSsRtCjHdMLjekAgxRn78+tPnJzd2aH8WTXEKDFxFtXVMYNkXq9YGGrHVh UeKAxtGQfGQ0kBPgDlBBtT4i/gtondIYAbhhxkC1ncKPw+AnVuhNEDxCz1uqB+kq0A/q ZFLCTUQCBhlX6MAkRXBgLXxDzwa26ItF9gs9MDwJ1upPdiYMPUxo8rmrdu5bP8JNrsLY JcmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5v/dwvyzqW0LrwkDssVFFMNck7V5COuSNYqzQhD5srA=; b=CGIqfnVlsE89llvhSZrrQ5INqz5NWZW53m7IZ55GLCAJYn8rTuX46BLsSDRuFqxeOI XeU87ETzFkPaEVYGsBX3Xr+4mI/Iih9UD8YX89q23nYVFrykPO8Ejg7LfPkGVMsDWZIH M6E+jfI/e+cVpfbQFMfDr5TU6nbF8MWypT1MYJ+5xxeAF2Izq5A2P2DWyva0BrhSBUms LIbNgKfmKK+hjksqBNLbH6pGPs5OeUucozvrS9om4tHnQ8vyb7OZxX7LvmsHtjIduQ3c ZSFTO6dG/WIEgXAQP/JBC4rDgGQkbTB3jmYyyw8X6iQf2QV4CdpoukDQrmTZMT3QHkau Ju6A== X-Gm-Message-State: AO0yUKXyt5fi0JdoDcA9j/8Q8OdGlt9heitHKNAqjCbhpZ+i/7SmyByc nXk60yv5KZUrLxL4ULVtbvtcPDW+o85a3WACDio= X-Received: by 2002:a17:90b:33d0:b0:234:d78:9b4c with SMTP id lk16-20020a17090b33d000b002340d789b4cmr12049982pjb.18.1677108443359; Wed, 22 Feb 2023 15:27:23 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s16-20020a17090ad49000b00234e6d2de3dsm5008918pju.11.2023.02.22.15.27.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 15:27:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/28] tcg: Remove branch-to-next regardless of reference count Date: Wed, 22 Feb 2023 13:26:51 -1000 Message-Id: <20230222232715.15034-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222232715.15034-1-richard.henderson@linaro.org> References: <20230222232715.15034-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 06209e6160..0992fb4f31 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2638,7 +2638,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) { @@ -2648,6 +2648,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 @@ -2661,21 +2677,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;