From patchwork Mon Jan 30 20:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 648577 Delivered-To: patch@linaro.org Received: by 2002:a17:906:c198:b0:888:9ecf:6623 with SMTP id g24csp895316ejz; Mon, 30 Jan 2023 13:01:12 -0800 (PST) X-Google-Smtp-Source: AK7set/X55Pf8poYuOg0GY6NPgT3cmHVHfK0UelbWINk0oiIS7a2hqBEShVzaT0jBq+7YYXPalPA X-Received: by 2002:a05:6214:2d10:b0:537:708d:3ff3 with SMTP id mz16-20020a0562142d1000b00537708d3ff3mr32458766qvb.16.1675112472378; Mon, 30 Jan 2023 13:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112472; cv=none; d=google.com; s=arc-20160816; b=C8DSC1FSvN4VhLAuRYX7ANDCBCHmTp7qEkChONT5cprSJZEnr+k06M8qbLSMMT7BUx YylL0yFLUlT34cyzC3hN/XKFcItST1CkGo/tIbjA8/zFh65MdrDJRuAS1YFJyIr4155R YplzsuTN5J/pRXNYUyQezD4VMN/TEuzCfRXTin2UBqM3af4plcRK0d86tjYj4ZmzRS3X kwMFDzufj7TH2k6tQu2W34Xlu68zDvaQ1YFU2z7BXx8JNBPYrfabu5GQVey6drUCYBan 6ejwEjXUQ8YfMxQQBV3pY1E4uEwjB4sjG+zU17Bxu68Q7WYpT3VBj/VT4MH8N6JNCPhs jnBw== 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=k0QQj1V4HE3kyNzJq2NL4R3goe68TydpAVl4hV+umL8=; b=E9URi46gQl4zHMekSvZqDU8itK6h9g3oU8SDW4nKwTM8avOY/C8D3C/om7qA+gmjw9 MTEo0K7tIPMloiYEQyvWFHkpZqwakMaftJgzqbDxm88k3HA85+55DLUd4mCrfCJkgxbJ 3rKKhSTK3R+yQtny2Tg8E6tSJ6PiDw4lGhRjeE56qADxIBqZwDRtd9n9Qxu0p3qeWXd2 WXbbR/ZrS2s90cF8LtK1uSKSO7nd01H7tUnuZPnUpvn6CitbZJ4TtyOr/7NyqShZeKgu ecJ0Z7UyJO5DgKBlrq89L3kTpWxHBHRagsiibzHb/adI+gD4w9AksScRvbyu0qMbIOv7 IICw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yRAcliXn; 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 r4-20020a056214212400b0053d689290a9si1166706qvc.256.2023.01.30.13.01.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Jan 2023 13:01:12 -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=yRAcliXn; 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 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) 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-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) 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) 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 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+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 --- 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 = false; 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 = 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 @@ -2659,21 +2675,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;