From nobody Thu Dec 26 22:41:23 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1675112472; cv=none; d=zohomail.com; s=zohoarc; b=QBOpMA+sZH7b8xT1gxmthTz1iZ6uWwa9yyA/3wkJPDNql6kUXRvxLqbiatCjdAnpY88ZVX7pZrLB4mY/jJ/DSDodzJ9Wxq+IGxFzLXJms7IeByFxCEvvTykI+0CIEl4qGTMzZng04GIRmTIX82N7n17Hv8ZU8aKcWc3wkk0Z260= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675112472; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k0QQj1V4HE3kyNzJq2NL4R3goe68TydpAVl4hV+umL8=; b=GLkvspnvUyTiVk5OkBBZww+QLOLr2DErMTW0LBko7Om82I9G0CAFraIAK7xAM5bj8ah9rgmWnYUvwbJZpnMA53xmLiSuhQ1tjjGoFDwYg0KRixwE6kRTCzzBs3vGq7StNepc84lcw65qLOb1yNM2h3NU8SHu8SDKajqvY2CBttM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675112472923337.9392807278599; Mon, 30 Jan 2023 13:01:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMbFw-0008EL-DK; Mon, 30 Jan 2023 16:00:00 -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 1pMbFm-0007Vf-9A for qemu-devel@nongnu.org; Mon, 30 Jan 2023 15:59:52 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pMbFk-0005EY-Mq for qemu-devel@nongnu.org; Mon, 30 Jan 2023 15:59:50 -0500 Received: by mail-pg1-x531.google.com with SMTP id r18so8566498pgr.12 for ; Mon, 30 Jan 2023 12:59:48 -0800 (PST) Received: from stoup.. (rrcs-173-197-98-118.west.biz.rr.com. [173.197.98.118]) by smtp.gmail.com with ESMTPSA id x10-20020aa79a4a000000b00593eb3a5e44sm102933pfj.37.2023.01.30.12.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 12:59:46 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k0QQj1V4HE3kyNzJq2NL4R3goe68TydpAVl4hV+umL8=; b=yRAcliXnSwbAEuxzit2uequ++G4dzmh94UIF+X26a8N64+vEebPbQvfKGU41x3blnX Pq0zWaoDCzZ7EvF22ej0Ubl3gXDjQ0VCGV4qomElNslvFvpPro8IYSeJ/HWwFOcN1oNw /AJ1K6ApMtK+EXP4HDszrYjXKaje7za/9sxYz9D0S+6MJJcc/0P/lbS25ObH0/wmGHaU TEd0teXJsHViXMYy0u//0VcE0lbvoxD6zq+mr6nN7F0gUkP037awJlm+lp+Zoi5YJIU8 z1yVGytSaycUOi/Pibg7j8FQrDLlUkyDNY044SgCpjr3E36jzGrCiiyW88yhMFIVs7OS PjtA== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k0QQj1V4HE3kyNzJq2NL4R3goe68TydpAVl4hV+umL8=; b=Qi+z/X+5ayPBLYzaEh8rkGtJ4Y+Zi0lPiQBA4rvYgLeyt77BwL3+w6T1YLGYdniR/I ufIHAcrPtO12ZHkfnhk44gSKE5uaVu84GOHJC1urASTfQAqOcopFV2LBmbVzagc/SnEy zFwq4/hUog2crYZv8Vji6x75QUne/zLyvmTzHlNY4Y6kiED63Wmh/ndqW1LrI1dSMj5S gdRVLtQ3mx9b3sFecJO0qIBbDiXs+JDxiesNWuqfVbXwCTkU+MkGm0fvC1xF1t+wJ5TU lYh3+RSDGMHjBpg3id97zoPqR3O8SEJDurVZ1PqYPNrO7I3vMAVXYxMZQAY7TqM17zDV jaqg== X-Gm-Message-State: AFqh2kqm1xsPRMpAWgNhVO8Qew8rfcvghgN+taywE0Yo4Cc9hGHdL59c EwNm4QAFU74gF4TbNiaMpFWxHt0BDVHzKnF0 X-Google-Smtp-Source: AMrXdXtL7itEulAkjBF0m8Lr7R3oXyPsCzvoulhkYmIFzqjG6c/Uf80Yuq+BFbttG6j2Tp3ghnPJdQ== X-Received: by 2002:a62:4e8e:0:b0:580:fb8e:3044 with SMTP id c136-20020a624e8e000000b00580fb8e3044mr52621079pfb.22.1675112387233; Mon, 30 Jan 2023 12:59:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, cota@braap.org Subject: [PATCH 04/27] tcg: Remove branch-to-next regardless of reference count Date: Mon, 30 Jan 2023 10:59:12 -1000 Message-Id: <20230130205935.1157347-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130205935.1157347-1-richard.henderson@linaro.org> References: <20230130205935.1157347-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1675112473841100001 Content-Type: text/plain; charset="utf-8" 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 --- tcg/tcg.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 0bb0bdbe43..fc0de1dccc 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2636,7 +2636,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 =3D false; =20 QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { @@ -2646,6 +2646,22 @@ static void reachable_code_pass(TCGContext *s) switch (op->opc) { case INDEX_op_set_label: label =3D 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 bra= nch + * and label had not yet been removed. + */ + op_prev =3D QTAILQ_PREV(op, link); + if (op_prev->opc =3D=3D INDEX_op_br && + label =3D=3D arg_label(op_prev->args[0])) { + tcg_op_remove(s, op_prev); + /* Fall through means insns become live again. */ + dead =3D false; + } + if (label->refs =3D=3D 0) { /* * While there is an occasional backward branch, virtually @@ -2659,21 +2675,6 @@ static void reachable_code_pass(TCGContext *s) /* Once we see a label, insns become live again. */ dead =3D false; remove =3D false; - - /* - * Optimization can fold conditional branches to unconditi= onal. - * If we find a label with one reference which is preceded= by - * an unconditional branch to it, remove both. This neede= d to - * wait until the dead code in between them was removed. - */ - if (label->refs =3D=3D 1) { - TCGOp *op_prev =3D QTAILQ_PREV(op, link); - if (op_prev->opc =3D=3D INDEX_op_br && - label =3D=3D arg_label(op_prev->args[0])) { - tcg_op_remove(s, op_prev); - remove =3D true; - } - } } break; =20 --=20 2.34.1