From nobody Thu Oct 2 10:18:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154577332034150.5910539179705; Tue, 25 Dec 2018 13:28:40 -0800 (PST) Received: from localhost ([127.0.0.1]:43373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbuFj-00028H-2h for importer@patchew.org; Tue, 25 Dec 2018 16:28:39 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtnH-0007Pi-SC for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:59:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbtnF-000161-Vw for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:59:15 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:33443) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbtnF-00013F-Px for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:59:13 -0500 Received: by mail-pf1-x436.google.com with SMTP id c123so7088468pfb.0 for ; Tue, 25 Dec 2018 12:59:12 -0800 (PST) Received: from cloudburst.home (c211-28-135-144.sunsh3.vic.optusnet.com.au. [211.28.135.144]) by smtp.gmail.com with ESMTPSA id t21sm48501628pgg.24.2018.12.25.12.59.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Dec 2018 12:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vWAeq5ZoD7ZS2xyd8XFJnj7+EV8VE96ympvHEkdeGZ8=; b=bO8Cc3QrSrdvtHVCz2SWPYGass0kq++UmVjfL91PbDjfm26g26DN/0f1SlesXRwWKR lsfimpFfpwUBkEo4u+zqkr+NzuR30NFfv5leOoYuuoU9OcE3OjMrSDmy+azW5VXSbX0N g6DOG5yaRmicg55Y6GAMw/c8HERIUpm9RuHUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vWAeq5ZoD7ZS2xyd8XFJnj7+EV8VE96ympvHEkdeGZ8=; b=KXRmvJU+J/908xXKmi9HVLFlwPjqzI4cEKobuCmKuM0txLTf1KD3TqQwJ3soaf4Kjg RT+c2zS3Cac/MTC7RZFgdJlIOvJ5+Iws4YTZT7s/P9se3CDnJL5vwX4NJ7EFJGNkv3Y+ 4cC0Mw+x3wsvXRrcxSqk2wLFEyMg38HHXetQC8A1iS8CzaJjWPjczJMFXekrSmrleqz0 ubM2lxfe3ZAW7NO+PhRifvH/qTkR/cNHrDzQ9n1KWLhQEabV4nH1U/5KMnFxJnQ4s++u eVwdCggDDgbJ+tG3j6NH6HeJktVh0Ji/ESQAIsiFrdWcGQ/X0jHonnNEFk/iS0kNJUrP GE2g== X-Gm-Message-State: AJcUukfuWQy0lXiXHopDoNBcZMr+JOmxkNgI0iVN3ksBi/qecqlQ+qxH LoQoxUQHz5YCU0pd4TRx601GW2o8j9A= X-Google-Smtp-Source: ALg8bN7EMlAnP0R+h0jWLX4bXl2MgoyyXiy7jZRf6PzaX2GkWoCXEBbD94UcvsFym9Zd0KkzfPsuBw== X-Received: by 2002:a63:104d:: with SMTP id 13mr16701824pgq.303.1545771551111; Tue, 25 Dec 2018 12:59:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2018 07:55:16 +1100 Message-Id: <20181225205529.10874-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181225205529.10874-1-richard.henderson@linaro.org> References: <20181225205529.10874-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::436 Subject: [Qemu-devel] [PULL 29/42] tcg: Add reachable_code_pass X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Delete trivially dead code that follows unconditional branches and noreturn helpers. These can occur either via optimization or via the structure of a target's translator following an exception. Reviewed-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tcg/tcg.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tcg/tcg.c b/tcg/tcg.c index 99afc65126..d2be550ab4 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2239,6 +2239,81 @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old= _op, TCGOpcode opc) return new_op; } =20 +/* Reachable analysis : remove unreachable code. */ +static void reachable_code_pass(TCGContext *s) +{ + TCGOp *op, *op_next; + bool dead =3D false; + + QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { + bool remove =3D dead; + TCGLabel *label; + int call_flags; + + switch (op->opc) { + case INDEX_op_set_label: + label =3D arg_label(op->args[0]); + if (label->refs =3D=3D 0) { + /* + * While there is an occasional backward branch, virtually + * all branches generated by the translators are forward. + * Which means that generally we will have already removed + * all references to the label that will be, and there is + * little to be gained by iterating. + */ + remove =3D true; + } else { + /* Once we see a label, insns become live again. */ + dead =3D false; + remove =3D false; + + /* + * Optimization can fold conditional branches to unconditi= onal. + * If we find a label with one reference which is preceded= by + * an unconditional branch to it, remove both. This neede= d to + * wait until the dead code in between them was removed. + */ + if (label->refs =3D=3D 1) { + TCGOp *op_prev =3D QTAILQ_PREV(op, TCGOpHead, 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); + remove =3D true; + } + } + } + break; + + case INDEX_op_br: + case INDEX_op_exit_tb: + case INDEX_op_goto_ptr: + /* Unconditional branches; everything following is dead. */ + dead =3D true; + break; + + case INDEX_op_call: + /* Notice noreturn helper calls, raising exceptions. */ + call_flags =3D op->args[TCGOP_CALLO(op) + TCGOP_CALLI(op) + 1]; + if (call_flags & TCG_CALL_NO_RETURN) { + dead =3D true; + } + break; + + case INDEX_op_insn_start: + /* Never remove -- we need to keep these for unwind. */ + remove =3D false; + break; + + default: + break; + } + + if (remove) { + tcg_op_remove(s, op); + } + } +} + #define TS_DEAD 1 #define TS_MEM 2 =20 @@ -3515,6 +3590,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) atomic_set(&prof->la_time, prof->la_time - profile_getclock()); #endif =20 + reachable_code_pass(s); liveness_pass_1(s); =20 if (s->nb_indirects > 0) { --=20 2.17.2