From patchwork Wed Mar 16 12:27:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1606121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=ky+juFQa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KJV1C3TPkz9s8s for ; Wed, 16 Mar 2022 23:28:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E536B388451E for ; Wed, 16 Mar 2022 12:28:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 0282B385781F for ; Wed, 16 Mar 2022 12:27:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0282B385781F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=n7nRwk3oAJKncOJg4cD6JyT2CDbqpAS3XokRX/L2QpA=; b=ky+juFQal+xwr+H8ENS/+Ixu9h r3Xm2pFFfy+y1EajoJK0L9YNQta6o9CdhpA1ZzYESypdYg0K/qvCWSIGAhJjooW6zEiOFzz6aSiGH j9dPbOfjUpaNFFUteIAjJXrWvZhc5xnuxpZAFRc8Bg745o99rOQQSNZ6D9xKDp+Ll49uYNVzhld2W wSRTrkfa/GqatfVcID9QGmQS/YfHE1bN6Vf7hPpEbgp7XcLeKv2vO4AXIgTFJ36PBg1ly3Jf5m/85 t1KK2ri6GDU+nkkbnF6JJGM1vjuGeFAIO4EAXKpbNQgld+8MMBhZb0xzT3ibZS2z7sJwBGLn7ex6l 7Xhs5WAw==; Received: from [185.62.158.67] (port=63072 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nUSkj-00048A-E1 for gcc-patches@gcc.gnu.org; Wed, 16 Mar 2022 08:27:45 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Generate an if instead of a switch with one case in genmatch. Date: Wed, 16 Mar 2022 12:27:45 -0000 Message-ID: <001001d83931$3defb510$b9cf1f30$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adg5MONoEVs5zaB2TMWFeyNXhB3wQA== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch is the first of two changes to genmatch that don't affect the executable code, but reduce the amount of debugging information generated in stage3 of a build, but adhering more closely to GNU style guidelines. This patch avoids generating a switch with a single case statement, instead preferring to use an "if (TREE_CODE (...) == SSA_NAME)" idiom. These should compile to the same instructions, but the switch requires more lines, especially when a debugger may set a break point on the switch, the case, or the (obligatory) final "default:;". This reduces the size of gimple-match.o by 53K on x86_64-pc-linux-gnu. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-03-16 Roger Sayle gcc/ChangeLog * gcc/genmatch.cc (dt_node::gen_kids_1): Introduce use_switch logic that prefers to generate an if statement rather than a switch containing a single case (and a default). Thanks in advance, Roger diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 2eda730..c4e22ef 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -2999,6 +2999,7 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, unsigned gexprs_len = generic_exprs.length (); unsigned fns_len = fns.length (); unsigned gfns_len = generic_fns.length (); + bool use_switch = true; if (exprs_len || fns_len || gexprs_len || gfns_len) { @@ -3011,7 +3012,30 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, else generic_exprs[0]->get_name (kid_opname); - fprintf_indent (f, indent, "switch (TREE_CODE (%s))\n", kid_opname); + if (gexprs_len == 0 && gfns_len == 0) + { + fprintf_indent (f, indent, "if (TREE_CODE (%s) == SSA_NAME)\n", + kid_opname); + use_switch = false; + } + else if (exprs_len == 0 + && fns_len == 0 + && gexprs_len == 1 + && gfns_len == 0) + { + expr *e = as_a (generic_exprs[0]->op); + id_base *op = e->operation; + /* id_base doesn't have a != operator. */ + if (!(*op == CONVERT_EXPR || *op == NOP_EXPR)) + { + fprintf_indent (f, indent, "if (TREE_CODE (%s) == %s)\n", + kid_opname, op->id); + use_switch = false; + } + } + + if (use_switch) + fprintf_indent (f, indent, "switch (TREE_CODE (%s))\n", kid_opname); fprintf_indent (f, indent, " {\n"); indent += 2; } @@ -3019,8 +3043,8 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, if (exprs_len || fns_len) { depth++; - fprintf_indent (f, indent, - "case SSA_NAME:\n"); + if (use_switch) + fprintf_indent (f, indent, "case SSA_NAME:\n"); fprintf_indent (f, indent, " if (gimple *_d%d = get_def (valueize, %s))\n", depth, kid_opname); @@ -3103,7 +3127,8 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, } } - fprintf_indent (f, indent, " break;\n"); + if (use_switch) + fprintf_indent (f, indent, " break;\n"); } for (unsigned i = 0; i < generic_exprs.length (); ++i) @@ -3115,12 +3140,18 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, else if (*op == SSA_NAME && (exprs_len || fns_len)) /* Already handled above. */ continue; - else + else if (use_switch) fprintf_indent (f, indent, "case %s:\n", op->id); - fprintf_indent (f, indent, " {\n"); - generic_exprs[i]->gen (f, indent + 4, gimple, depth); - fprintf_indent (f, indent, " break;\n"); - fprintf_indent (f, indent, " }\n"); + + if (use_switch) + { + fprintf_indent (f, indent, " {\n"); + generic_exprs[i]->gen (f, indent + 4, gimple, depth); + fprintf_indent (f, indent, " break;\n"); + fprintf_indent (f, indent, " }\n"); + } + else + generic_exprs[i]->gen (f, indent + 2, gimple, depth); } if (gfns_len) @@ -3157,7 +3188,8 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, if (exprs_len || fns_len || gexprs_len || gfns_len) { indent -= 4; - fprintf_indent (f, indent, " default:;\n"); + if (use_switch) + fprintf_indent (f, indent, " default:;\n"); fprintf_indent (f, indent, " }\n"); }