From patchwork Fri Mar 3 22:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 658475 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp689161wrb; Fri, 3 Mar 2023 14:32:02 -0800 (PST) X-Google-Smtp-Source: AK7set8yRRgxtDSV+Sczik0ZnPosUD3u0flfmgNXhwgIZcPk4EagyGEkP5va1RwjIHLEFahTRqi2 X-Received: by 2002:ac8:4e56:0:b0:3b1:ca9c:6c38 with SMTP id e22-20020ac84e56000000b003b1ca9c6c38mr5561871qtw.51.1677882722220; Fri, 03 Mar 2023 14:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677882722; cv=none; d=google.com; s=arc-20160816; b=p5+KArapSp1/IOGl6uIJGkt5FEYrOJMoxs2JsqvqwO8ZRC0V5MxZmBTXSKy219WaCk HMRc0f268AQ3A5VifSl9ewnoSVHId0+4jh4IupeV+CiNpGw7nITHmSEAIHvYxXMoClOd 0ExR/oA0s6dtnTMEWRuP3v6lIPk0HBUJa5BZX8XMOQ5vNT5KSWzQa4+vyqbsGrtw7s07 rZ1Qltf/lynwyntUC8emJ9ZzWbP855GgRNcy5NDR5MsmnwDyxbI7SjFKMW+G7v7ixv7v oWYJJQK2oKeIqVBk2ez3L5LyJeOSzZUJI/wmW0gvbMPbU+zVDcnnzyeky64RfsT27zm2 CwTA== 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=p3fG4f/WbptHUCzZ+xxjE7jM7Pmvnki7ftb6PyqTKjk=; b=BDbnZRu9kZpr2EhsLGN8xNE+cYCvNgEKQ898AE0enzUvbjjBEVRcN15S18z/ijio6m atRXqEoh151iyY+RbWS/ssPjqzG3qQshY9ACGvngQnCGRLkzXrbXMq+b3Z//A45m2wZL xWz2Png12q+W1ppsT52R2/CllC7JEzC/HJNIXdoT5dQEmrKyHf+DBeZjddQ04xDsM97N vTU76YLneRUmvBOb1/pbshG/xymelkUtUylVPm1nTOXelyIvKbsWCEku3QPxuC51PZQl WlnK/KV9DUh015P7HVThVWBgy2wmJ/d27nq0JDNV1bqLnRa8Uvxq4Mk5RB98H7z7qtiY 8jgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QDay1Oks; 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 ay35-20020a05620a17a300b0073ba5323d3csi3078962qkb.703.2023.03.03.14.32.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Mar 2023 14:32:02 -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=QDay1Oks; 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 1pYDvy-0005tQ-0R; Fri, 03 Mar 2023 17:31:26 -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 1pYDvg-0005Rn-GG for qemu-devel@nongnu.org; Fri, 03 Mar 2023 17:31:08 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pYDvZ-0007vb-Di for qemu-devel@nongnu.org; Fri, 03 Mar 2023 17:31:08 -0500 Received: by mail-pj1-x1036.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so7709903pjh.0 for ; Fri, 03 Mar 2023 14:31:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677882660; 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=p3fG4f/WbptHUCzZ+xxjE7jM7Pmvnki7ftb6PyqTKjk=; b=QDay1OksE6n8YpgBiktPBEmWYUlcSLyiRBD2X8FXAmb4FDEEFzluiCCrB0AbQkfCZM p/YI3O8DwULQ5F5SdzGh3xFxO07Pfs7AU6wubesb/rW8G+4mTgkm9v0HJNOWurX/M1w/ 7T7HC50P7pKCqMZfOpbpnAvd8ZoT42os6yVfcIk+BDlIigGsMLfj3/7HIgM3fcgxsJiW 7bcGz28viOeYtlHIaPIGZ9im3Hz5aJh1gEmRsXss41RvlAxBv0d4tKuRiDRmlAfGNSb7 6Bixy63Gat6emo1bsd13I027bsXMfIQi7YW9KibRvy5wHiWOl3xRmEW/bjmf8v9uBh1O v8Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677882660; 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=p3fG4f/WbptHUCzZ+xxjE7jM7Pmvnki7ftb6PyqTKjk=; b=mY/d7DNfVXWKsd3OrMgvquWJlRIEO+EY0vm2BgaMb5pUGnuqm/l7ITsvTCZC7r5bpK 85b1ynqPK4oh6AQ/xs9OJfWZAj0z07sFGeokr3vnhYnp2EkgqCEEO6M22HN3dew6/u8b VfvZYcDh1h86QIkyvdOiV24z9vTamyZBWOj0fl0XXazYuO8hg4Zp25Yn9s43/CVWXaps 5IxqpSxhw4e9bpNBT0QMStJknkHk8AJI4a+OCMRPztcY9WiJVGHBkNbE639MHi1AgroY w6pRNUUmeH4wMYCH221JLV9cjhHOO8Z5lCwrJMe8ZubCsVvyiwN2v74m9orR/EUv6kUG Vnmg== X-Gm-Message-State: AO0yUKX1YK4RSKuPiR+pBCWh6/XPgZk35b51oW2fzENn1gzicqJqJvsc dlprdSMtXHkh/OqhRIUxRrvyERwaN3yTcvsIeVKoOw== X-Received: by 2002:a17:902:ecc1:b0:19e:23c1:4c2e with SMTP id a1-20020a170902ecc100b0019e23c14c2emr4014395plh.59.1677882659977; Fri, 03 Mar 2023 14:30:59 -0800 (PST) Received: from stoup.. (174-21-74-159.tukw.qwest.net. [174.21.74.159]) by smtp.gmail.com with ESMTPSA id b5-20020a170902b60500b0019a87ede846sm1963742pls.285.2023.03.03.14.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 14:30:59 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: anjo@rev.ng, tsimpson@quicinc.com Subject: [PATCH 2/2] tcg: Merge two sequential labels Date: Fri, 3 Mar 2023 14:30:56 -0800 Message-Id: <20230303223056.966286-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230303223056.966286-1-richard.henderson@linaro.org> References: <20230303223056.966286-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 Remove the first label and redirect all uses to the second. Signed-off-by: Richard Henderson Reviewed-by: Taylor Simpson --- tcg/tcg.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index a8ec11dfb9..88614102cd 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2627,6 +2627,31 @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op, return new_op; } +static void move_label_uses(TCGLabel *to, TCGLabel *from) +{ + TCGLabelUse *u; + + QSIMPLEQ_FOREACH(u, &from->branches, next) { + TCGOp *op = u->op; + switch (op->opc) { + case INDEX_op_br: + op->args[0] = label_arg(to); + break; + case INDEX_op_brcond_i32: + case INDEX_op_brcond_i64: + op->args[3] = label_arg(to); + break; + case INDEX_op_brcond2_i32: + op->args[5] = label_arg(to); + break; + default: + g_assert_not_reached(); + } + } + + QSIMPLEQ_CONCAT(&to->branches, &from->branches); +} + /* Reachable analysis : remove unreachable code. */ static void __attribute__((noinline)) reachable_code_pass(TCGContext *s) @@ -2642,6 +2667,24 @@ reachable_code_pass(TCGContext *s) case INDEX_op_set_label: label = arg_label(op->args[0]); + /* + * Note that the first op in the TB is always a load, + * so there is always something before a label. + */ + op_prev = QTAILQ_PREV(op, link); + + /* + * If we find two sequential labels, move all branches to + * reference the second label and remove the first label. + * Do this before branch to next optimization, so that the + * middle label is out of the way. + */ + if (op_prev->opc == INDEX_op_set_label) { + move_label_uses(label, arg_label(op_prev->args[0])); + tcg_op_remove(s, op_prev); + op_prev = QTAILQ_PREV(op, link); + } + /* * Optimization can fold conditional branches to unconditional. * If we find a label which is preceded by an unconditional @@ -2649,7 +2692,6 @@ reachable_code_pass(TCGContext *s) * 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);