From patchwork Wed Mar 1 02:56:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 657768 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp3269773wrb; Tue, 28 Feb 2023 18:59:55 -0800 (PST) X-Google-Smtp-Source: AK7set87pr8RA4qb45TcQ0agJuCfG1nxxRdxtcah8oaX2ENpfen0jZlfbkUuDO9E6UkUesZ23GU3 X-Received: by 2002:a05:6214:c46:b0:56e:941d:a4b3 with SMTP id r6-20020a0562140c4600b0056e941da4b3mr9197372qvj.7.1677639595489; Tue, 28 Feb 2023 18:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677639595; cv=none; d=google.com; s=arc-20160816; b=nS9Q9YIRF1cvC4qJdeck8cOiy98eGVBGvtlWAf6x7kwBxZjQLhTqSBaO5i53GGUEhn 53MJUA4q54eX9hvodgxmqJHmEbHFahwLAlEFhgZ9Db0uaPEubBA0HElgMiBVNRJLPR7e F7qsq45QJ+LqPBnyRIWDxeIiy2Rn1pMBrBnK9YMcjiYotgo4hiPJS9aHxVWyFQopmGyy wm7yH9v714R4P3CqhGcp+bzWrQCFvhTI7h2qVi/zgxG9OblLagib1oJx2btxrQYG1OSV TjnJclQKkLZw7Ap+i+I6UMwSiMyM5REiWUqKM+4YbWl6Wczcfxb9/5aQqXgD2LAFbqVA ewhQ== 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=krNMuzPiCobn56SlmIYf/PRBtrXsN7JQ0TzAirhgLBc=; b=weOmzmmBNtSC/Yxs/PsrlrUUxw2+065ExphY/cJVc7hC7UsooUxyyGpQ4ZDRR3MLsn iqbS/B0K3PfY7zXUDhgbDHIvVKH0L6xuD4roVE4UU5vx9nGewVgZfJB7UVHZb6jGoBQT THkwxqcsqYRb4E6T/9SN4MUFn/09JEO7oXR8uSHmb8mBAIBidM3ewjUUfRhAB/3vuVJ9 IYdk9YVlQqVN16F3WOKj1lOESeKWJpswLAdGXDMyBPJeemVHhyQjMFy8EOcSaANpY8T6 Xa3LGhuTpQYkb+ApYvYJrVKwqDpybXVPpzQ+D7/Wt7X1B37rgnT3YlIddMSoZtzRwM7H 0L+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dR3IcZ+t; 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 u25-20020a0cb699000000b0056c07f12377si10411441qvd.158.2023.02.28.18.59.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Feb 2023 18:59:55 -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=dR3IcZ+t; 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 1pXCf8-0002Le-34; Tue, 28 Feb 2023 21:57:50 -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 1pXCf7-0002Cw-6Q for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:57:49 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCf5-0003Jo-9n for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:57:48 -0500 Received: by mail-pl1-x633.google.com with SMTP id n6so11178862plf.5 for ; Tue, 28 Feb 2023 18:57: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=krNMuzPiCobn56SlmIYf/PRBtrXsN7JQ0TzAirhgLBc=; b=dR3IcZ+tbUgEiCOHy6CXhkFSVsWobdene7EX/3B8S7+xMQOZACDwF4kE1/5B5kQGAs S4afR+M7jxOrsl7IYPzNaOt6KB+4H6Zo+azNq9TIcknKOjBdivTiamjKVC3vz1kyZYwx G0c0LOB3fz10BkngFyk3dJSZrPwoR1pLMjHvp//z3OjlRe6K82WtcG8iWzTqHpzDA1C2 7P8L32w/npG9xa3l20st/YfiM2BSahKSacFCosI4wnBcBEUUVuG7w0vbh5iuFsHYOg0/ PbriF1f5yD75TV8IXduBry0iuFrcALqx4OTX2Ijrbd/HajI1vUJoVIu+JB0Zq3dgKuNd YHqQ== 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=krNMuzPiCobn56SlmIYf/PRBtrXsN7JQ0TzAirhgLBc=; b=jXkdEEcsp3xnH8bz0+Gdd+3iWdp7buJU9o2q4g55rT5l8cflJnFwdwaGeeI9Z3StP3 z8JPk3RwTjOQEn+6mFBFvhmFM5pIqfNGcNnQva4Xb6zaNpNll65e9QW6UU6uYcegDDWC oIYXBry0Elz2s44JA3HiNadXF9tU7b1NlihyeHR8wq+hl3FI4KYdco0zjhQUXNaWUb0w xS9EcjS6QxLF1S9roQhFokJ1BNo7y1alKEvItlaOsHrnDv+e1+9qJ9N+DFNFWquO5IWW aYkESToOvlZW0eGGZH52pMtzfFgriCORXWjzskYsH3b0GYXJlBDLIXlZuyo04JdiXOrm NWOQ== X-Gm-Message-State: AO0yUKVom67mkPzoGJOrdCgWw5J/+/2dEaEfj3oNttGUxGn1vqUvJVHj TSLQoBNyf9zkpfIFyts2S/rSQg1sIjxTHAXba7I= X-Received: by 2002:a17:903:1110:b0:19c:ba57:a869 with SMTP id n16-20020a170903111000b0019cba57a869mr5001911plh.13.1677639465883; Tue, 28 Feb 2023 18:57:45 -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 jg15-20020a17090326cf00b0019adbef6a63sm7210120plb.235.2023.02.28.18.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:57:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 35/62] tcg: Remove branch-to-next regardless of reference count Date: Tue, 28 Feb 2023 16:56:16 -1000 Message-Id: <20230301025643.1227244-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025643.1227244-1-richard.henderson@linaro.org> References: <20230301025643.1227244-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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 855e4cc537..9739e4830f 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2637,7 +2637,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) { @@ -2647,6 +2647,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 @@ -2660,21 +2676,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;