From nobody Tue May 7 12:37:27 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677882686; cv=none; d=zohomail.com; s=zohoarc; b=lJiurVIq7APZTtS7qWlhAML+hx2rcSGufRWhsA0lUp+JWzUJgjeqE2fijQ+gF5VoZ9JfUEDmsBiqM/UFjpkXavnXbmswOlRasQgVozXaEZrTV1hbw+ZF6faWPrYt04bHSa50tR5D93lPSYeP3kx3iGpjseMW0iePRuCW7xzWfjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677882686; 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=UjrCAUK9hqpmBfed71834dqlSNQejblGv7FQtUqKrwI=; b=H80fbLl/SK0t1GetlJpTPuqW6tEsdbpncvOP4XDAQq+kDzz3nz55mKTudgae/qWfbpSZQGXvTSVDWjoQ7f/uWALYeNY3Uo9RfknrWzJ1hAhAs2cq89k7hm7ToHz1s+237anZMZawsFSDxztZ4xZoXCmSlC2xPy2apQyaIxhPSXE= 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+importer=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 1677882686743734.7926646476592; Fri, 3 Mar 2023 14:31:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pYDvh-0005WD-CL; Fri, 03 Mar 2023 17:31:14 -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-0005Pk-4V for qemu-devel@nongnu.org; Fri, 03 Mar 2023 17:31:08 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pYDvY-0007vH-RK for qemu-devel@nongnu.org; Fri, 03 Mar 2023 17:31:06 -0500 Received: by mail-pj1-x102b.google.com with SMTP id x34so4173194pjj.0 for ; Fri, 03 Mar 2023 14:31:00 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 14:30:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677882659; 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=UjrCAUK9hqpmBfed71834dqlSNQejblGv7FQtUqKrwI=; b=qxQ0FrAabuhgYiQxyv5HcctgsmWMlbWvjJG3NOa2FhqfpeM5jRFAUA1HZ4EZLszUnn dRtkA7Uc/QEZBZ/Zxkaa/u0fcTHeAarg4QP/7pz5RGGVvrKs/N1ouiJYe0GA3Q6g1szr LqlaBk1GbCw1rc2JC2m0g1UhR4TnwmgsE74L0m/FCOo39wd/UcWDOaU28XlsNzek88GS Jh55YP+/XG+LJyL6elDsj0XLb307T83kE+5ZX3Ldp6XQ9XP22k2ziV785aF11G650gHw m7L1Nm7ZTZlKH/30+ofZUZx2Kabv0exSRA6YXhynyqi/ei6bvib9sVOLRio18DSqYCYj ko4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677882659; 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=UjrCAUK9hqpmBfed71834dqlSNQejblGv7FQtUqKrwI=; b=EtHSYj91OJsAt6ohiWIqrSl+wGNRlAjhYtlGNrC+bApFLsoLlCOw50mRv6RnBCJ+Cn fbMxCzr1vjPY0z3J38rEBarbYiZ1tH2s3ZGhS09O8jdaRWRZwNxSld8iJp8YgM/IRYMq HZtbr743dMnu0wwE5i2EvquUxMgUgoJSas1B+Emdhf+yemGD+034yi94XIP6rYR8A7QW UlmXyS0XkWT+MCD7CNNshxuJp1h1ch5l+CPp9c4fioVqeds5HXg22Wh1Ar6ZocZDeVmr N01ddaN6RMVeQCsa1JipPa8mxgtemVgM6bzg9fifoQOtvD0GjYUD0PhSZ2hK/enJz87G XtXA== X-Gm-Message-State: AO0yUKWhDQJ+YmOf91Cl0eocp/TNZm7vdPrts7gVx7MjnvuCIu9y50lo Y0rfX2+NrKlne+Bg/B5psF4nmIv8443XCQhYaKAHmQ== X-Google-Smtp-Source: AK7set/IQVXvIMnqhxEi/vBR/bXh5gHHM+RM6nAKFzUBXGERGmi05+trD4fVLTFp/bMSDYj/jLrcnA== X-Received: by 2002:a17:902:760d:b0:19c:e6c8:db16 with SMTP id k13-20020a170902760d00b0019ce6c8db16mr2833529pll.27.1677882659154; 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 1/2] tcg: Link branches to the labels Date: Fri, 3 Mar 2023 14:30:55 -0800 Message-Id: <20230303223056.966286-2-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 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677882688145100001 Content-Type: text/plain; charset="utf-8" This allows us to easily find all branches that use a label. Since 'refs' is only tested vs zero, remove it and test for an empty list instead. Drop the use of bitfields, which had been used to pack refs into a single 32-bit word. Signed-off-by: Richard Henderson Reviewed-by: Taylor Simpson Tested-by: Taylor Simpson --- include/tcg/tcg-op.h | 7 +------ include/tcg/tcg.h | 19 +++++++++++++------ tcg/tcg-op.c | 22 +++++++++++++++++++--- tcg/tcg.c | 30 ++++++++++++++++++++---------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h index 353d430a63..70856147c5 100644 --- a/include/tcg/tcg-op.h +++ b/include/tcg/tcg-op.h @@ -259,12 +259,7 @@ static inline void gen_set_label(TCGLabel *l) tcg_gen_op1(INDEX_op_set_label, label_arg(l)); } =20 -static inline void tcg_gen_br(TCGLabel *l) -{ - l->refs++; - tcg_gen_op1(INDEX_op_br, label_arg(l)); -} - +void tcg_gen_br(TCGLabel *l); void tcg_gen_mb(TCGBar); =20 /* Helper calls. */ diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 7e2b954dbc..0dc88011ce 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -238,16 +238,23 @@ struct TCGRelocation { int type; }; =20 +typedef struct TCGOp TCGOp; +typedef struct TCGLabelUse TCGLabelUse; +struct TCGLabelUse { + QSIMPLEQ_ENTRY(TCGLabelUse) next; + TCGOp *op; +}; + typedef struct TCGLabel TCGLabel; struct TCGLabel { - unsigned present : 1; - unsigned has_value : 1; - unsigned id : 14; - unsigned refs : 16; + bool present; + bool has_value; + uint16_t id; union { uintptr_t value; const tcg_insn_unit *value_ptr; } u; + QSIMPLEQ_HEAD(, TCGLabelUse) branches; QSIMPLEQ_HEAD(, TCGRelocation) relocs; QSIMPLEQ_ENTRY(TCGLabel) next; }; @@ -487,7 +494,7 @@ typedef struct TCGTempSet { #define SYNC_ARG (1 << 0) typedef uint32_t TCGLifeData; =20 -typedef struct TCGOp { +struct TCGOp { TCGOpcode opc : 8; unsigned nargs : 8; =20 @@ -506,7 +513,7 @@ typedef struct TCGOp { =20 /* Arguments for the opcode. */ TCGArg args[]; -} TCGOp; +}; =20 #define TCGOP_CALLI(X) (X)->param1 #define TCGOP_CALLO(X) (X)->param2 diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index f2269a1b91..befc7c000d 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -84,6 +84,22 @@ void tcg_gen_op6(TCGOpcode opc, TCGArg a1, TCGArg a2, TC= GArg a3, op->args[5] =3D a6; } =20 +/* Generic ops. */ + +static void last_is_label_use(TCGLabel *l) +{ + TCGLabelUse *u =3D tcg_malloc(sizeof(TCGLabelUse)); + + u->op =3D tcg_last_op(); + QSIMPLEQ_INSERT_TAIL(&l->branches, u, next); +} + +void tcg_gen_br(TCGLabel *l) +{ + tcg_gen_op1(INDEX_op_br, label_arg(l)); + last_is_label_use(l); +} + void tcg_gen_mb(TCGBar mb_type) { if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { @@ -216,8 +232,8 @@ void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TC= Gv_i32 arg2, TCGLabel *l) if (cond =3D=3D TCG_COND_ALWAYS) { tcg_gen_br(l); } else if (cond !=3D TCG_COND_NEVER) { - l->refs++; tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_arg= (l)); + last_is_label_use(l); } } =20 @@ -1474,7 +1490,6 @@ void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, = TCGv_i64 arg2, TCGLabel *l) if (cond =3D=3D TCG_COND_ALWAYS) { tcg_gen_br(l); } else if (cond !=3D TCG_COND_NEVER) { - l->refs++; if (TCG_TARGET_REG_BITS =3D=3D 32) { tcg_gen_op6ii_i32(INDEX_op_brcond2_i32, TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2), @@ -1483,6 +1498,7 @@ void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, = TCGv_i64 arg2, TCGLabel *l) tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_arg(l)); } + last_is_label_use(l); } } =20 @@ -1493,12 +1509,12 @@ void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg= 1, int64_t arg2, TCGLabel *l) } else if (cond =3D=3D TCG_COND_ALWAYS) { tcg_gen_br(l); } else if (cond !=3D TCG_COND_NEVER) { - l->refs++; tcg_gen_op6ii_i32(INDEX_op_brcond2_i32, TCGV_LOW(arg1), TCGV_HIGH(arg1), tcg_constant_i32(arg2), tcg_constant_i32(arg2 >> 32), cond, label_arg(l)); + last_is_label_use(l); } } =20 diff --git a/tcg/tcg.c b/tcg/tcg.c index 5cccc06ae3..a8ec11dfb9 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -282,6 +282,7 @@ TCGLabel *gen_new_label(void) =20 memset(l, 0, sizeof(TCGLabel)); l->id =3D s->nb_labels++; + QSIMPLEQ_INIT(&l->branches); QSIMPLEQ_INIT(&l->relocs); =20 QSIMPLEQ_INSERT_TAIL(&s->labels, l, next); @@ -2519,23 +2520,32 @@ static void process_op_defs(TCGContext *s) } } =20 +static void remove_label_use(TCGOp *op, int idx) +{ + TCGLabel *label =3D arg_label(op->args[idx]); + TCGLabelUse *use; + + QSIMPLEQ_FOREACH(use, &label->branches, next) { + if (use->op =3D=3D op) { + QSIMPLEQ_REMOVE(&label->branches, use, TCGLabelUse, next); + return; + } + } + g_assert_not_reached(); +} + void tcg_op_remove(TCGContext *s, TCGOp *op) { - TCGLabel *label; - switch (op->opc) { case INDEX_op_br: - label =3D arg_label(op->args[0]); - label->refs--; + remove_label_use(op, 0); break; case INDEX_op_brcond_i32: case INDEX_op_brcond_i64: - label =3D arg_label(op->args[3]); - label->refs--; + remove_label_use(op, 3); break; case INDEX_op_brcond2_i32: - label =3D arg_label(op->args[5]); - label->refs--; + remove_label_use(op, 5); break; default: break; @@ -2647,7 +2657,7 @@ reachable_code_pass(TCGContext *s) dead =3D false; } =20 - if (label->refs =3D=3D 0) { + if (QSIMPLEQ_EMPTY(&label->branches)) { /* * While there is an occasional backward branch, virtually * all branches generated by the translators are forward. @@ -4891,7 +4901,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb,= target_ulong pc_start) bool error =3D false; =20 QSIMPLEQ_FOREACH(l, &s->labels, next) { - if (unlikely(!l->present) && l->refs) { + if (unlikely(!l->present) && !QSIMPLEQ_EMPTY(&l->branches)) { qemu_log_mask(CPU_LOG_TB_OP, "$L%d referenced but not present.\n", l->id); error =3D true; --=20 2.34.1 From nobody Tue May 7 12:37:27 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677882722; cv=none; d=zohomail.com; s=zohoarc; b=jLcys6+SuhkEkLhFY7iNwatGo/U5Inqr0rhSMR/pVjPC/N2GVy8NpVRAvcE5r2qjsW2AMrNM2DzZ6nW4X063sVpKxMI+rQ0d0qQ8STwB4kYNkK7yBrkNTeinzGkOy9PJ/JsuR0jASnopwWbHwkKk1aJrLDdIAUpJyf3L+F7oKkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677882722; 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=p3fG4f/WbptHUCzZ+xxjE7jM7Pmvnki7ftb6PyqTKjk=; b=Ruxdjuib8CHUxezFafi5bmLFRcM2YfrHGptqnGL2MsSgruQ1mCqC5U6XwT+312WSrAfKdoQfX1RCLDI01qb8VuhYEOvtqE8/KQyvj6WicNFks1SecMa0vflRzBZFwz2SU9Oiw2k4fOkE7xL9jmoxnhgbXu927RuG9YzNgN+Ah3A= 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+importer=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 1677882722651205.77469245115844; Fri, 3 Mar 2023 14:32:02 -0800 (PST) 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) 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) 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-Google-Smtp-Source: AK7set+i0GNlc3DNfUoay/EvhQmSnjXx1o24h2p+oHaxqdo9RgP4pzPq6WOvjDh2h0oF/EavBQC/5Q== 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) 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 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677882723980100003 Content-Type: text/plain; charset="utf-8" Remove the first label and redirect all uses to the second. Signed-off-by: Richard Henderson Reviewed-by: Taylor Simpson Tested-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; } =20 +static void move_label_uses(TCGLabel *to, TCGLabel *from) +{ + TCGLabelUse *u; + + QSIMPLEQ_FOREACH(u, &from->branches, next) { + TCGOp *op =3D u->op; + switch (op->opc) { + case INDEX_op_br: + op->args[0] =3D label_arg(to); + break; + case INDEX_op_brcond_i32: + case INDEX_op_brcond_i64: + op->args[3] =3D label_arg(to); + break; + case INDEX_op_brcond2_i32: + op->args[5] =3D 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 =3D arg_label(op->args[0]); =20 + /* + * Note that the first op in the TB is always a load, + * so there is always something before a label. + */ + op_prev =3D 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 =3D=3D INDEX_op_set_label) { + move_label_uses(label, arg_label(op_prev->args[0])); + tcg_op_remove(s, op_prev); + op_prev =3D 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 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); --=20 2.34.1