From patchwork Sat Feb 25 08:59:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 656446 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1352249wrb; Sat, 25 Feb 2023 01:03:07 -0800 (PST) X-Google-Smtp-Source: AK7set+8Lgu1N5XFl2HtjLSLlZJ+A0lpGWBTRUZEJ9i76VOd/v2BvhFS/brdgltjUdBVDYOJ3lyW X-Received: by 2002:a05:6214:c2d:b0:56e:b5a0:29eb with SMTP id a13-20020a0562140c2d00b0056eb5a029ebmr35964729qvd.40.1677315786849; Sat, 25 Feb 2023 01:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677315786; cv=none; d=google.com; s=arc-20160816; b=oj9ECaiSyAxbkUurLM8RGU4cNU6zgX5BqfMyPxQEvjWMZiqpqhC2wqsSI0UvUYtQ8V 6XAHYSaq64QLST5bNjpEXl9Q3XfG1+E+LF6ryjJTH2l3syGX+BLaRiKrf/B2/QbxABxC BTdkH2XLpWvx2QM2SjNpwAfcGtbPX4+PsrABFtWsqMRZuVKujjjdPpsTVZedKnfOOtcj 1JIxGhqArstPptDm4PcRDcSV1q4iFTLuE/7HadABIGJUwfqGAuw2N70d/ri8AtcWbDuM ndwhsOhZaQ9m/nxe+4fAfPAfxqm/SjbGIbwBTmryBIDBIYL3pSCET7MHEu13u5wEL9q6 um3g== 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:cc:to :from:dkim-signature; bh=KgU8jRRsy/4dDTOMKHuklv2pdjkeQjC0sYzVe39pJ+4=; b=WJwKc0n0W4dL26p5K4uo8gAwGy2xWrcN4DAL4xuNjQhpKsWXVu3WOiIOlju1K36yvu rBKtEu4X91T9k9Y3E+q+BETlcUm4mfyDdDBv8k+Rzz45YAixUGXIRqqheOjYx7+klMjv MYTDmum41nwN1+OrqkkCqW+dl+t2Gspg1ljzTpeKwpehFAH4I4UAnMBDX0p2kdztz0xN RzoO6w/4Pb82GxQTgV+ya58UP0MJ5pIAGCeo1XQgRuMNlWRB+V1pnvcQhw/zi3LsOeBA oGhXFYvILbIqNRdaU5mH31V0AldqOt2gUXUv/9Bmh143qt1GWV0x+tBlujEUlVU014MK q0gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QIKkmIpc; 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 x188-20020a3763c5000000b007415ec4cd62si1345775qkb.188.2023.02.25.01.03.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 Feb 2023 01:03:06 -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=QIKkmIpc; 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 1pVqPQ-0000NG-Gd; Sat, 25 Feb 2023 04: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 1pVqPO-0000MI-DT for qemu-devel@nongnu.org; Sat, 25 Feb 2023 03:59:59 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVqPN-0004pK-0J for qemu-devel@nongnu.org; Sat, 25 Feb 2023 03:59:58 -0500 Received: by mail-pj1-x1029.google.com with SMTP id k21-20020a17090aaa1500b002376652e160so1621922pjq.0 for ; Sat, 25 Feb 2023 00:59:56 -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=KgU8jRRsy/4dDTOMKHuklv2pdjkeQjC0sYzVe39pJ+4=; b=QIKkmIpc6Z3Xmc110LJe5rbi0YY89jxj2bDY9lg50WkyBHD4ud/2GeALV/qzs1McxF THhqQ3QetjQoOYk7BsPEiNclrjbOsakB4BqeCI8qU0KOFmPWgaqMwsdAMp8ZqKMB3acR 3ZzMcD8jg4jGBuhQVA49oGarMJn2isgirw9RGtf646rIIIJrY5nm70rEJWteEm59RVKr 2qMtJyJgn5sJqDPq5lSNYykjHNGAfvCZLpINXtrsU7dX7Wrj4oNC1P/l6NffkOz6cUC1 WMweLpuEiCQ118Z7vaM2KisqSvOJlj11DQfDEg1HIGj1Bq8CLZbxQthEUeO1h0eflQER 7Jxw== 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=KgU8jRRsy/4dDTOMKHuklv2pdjkeQjC0sYzVe39pJ+4=; b=kMSoPsIjeY4ds4rjok6+Bs9pYzyJSVeHr36eTeCgDKMzewc2Q5w7y0aK4JzvRfKKAB 1pwY+zmve+4Dll1F+q4lv+bawT99r2yaUCVF0/0IRZ4weY0zeWkRBGPxVyxmkCMoACzp 5mJzmR9WVcbXXUcOq1ccPwUUekY0gdzpCIDxBB/H7bF1sSa2wOXOoAUmXBnlVSn14//2 7m6clLnmxLW+7zPFOyC8pWa+kTcCwNgDr7oIXW1Hwu4FVobVDSgL7mPyOCZvAeF/obR2 RlNpdoRrEO1Sklqg4CuBHrc6/PoGZ8VK4D8gUzgzoZOo1pLHeKvYaz1TRd/RbpJKMeCK MKxg== X-Gm-Message-State: AO0yUKXpGSyJnbde35/9m7qkVnlFBijGzWkJnN4wQGsWcqTQc1N5MurL Y386J6k/9kJGcykQANF3raEHZmKWQoGWQ/JqxmU= X-Received: by 2002:a17:902:ec86:b0:196:11b1:101d with SMTP id x6-20020a170902ec8600b0019611b1101dmr21029494plg.28.1677315595510; Sat, 25 Feb 2023 00:59:55 -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 s17-20020a639251000000b00502ecb91940sm715546pgn.55.2023.02.25.00.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 00:59:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 04/30] tcg: Remove branch-to-next regardless of reference count Date: Fri, 24 Feb 2023 22:59:19 -1000 Message-Id: <20230225085945.1798188-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230225085945.1798188-1-richard.henderson@linaro.org> References: <20230225085945.1798188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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. Reviewed-by: Philippe Mathieu-Daudé 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 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;