From patchwork Wed Mar 16 12:29:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 51997 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7850F384387A for ; Wed, 16 Mar 2022 12:31:28 +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 6B681384387A for ; Wed, 16 Mar 2022 12:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B681384387A 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=HCrHTpo4DauSXWslI6wn09eH7qm+PA8btIfd6+rQsdg=; b=rpvUppGR+cY7Jbh5iHaZG2yxVm dcJIEB/rO6AXKEKjweGarb8AuWI47wMmnrQShjv0AE9KM2XjvqtscFc9wF40wWqsgHmEze6Zazcud esaHC1uiSW08zJwvZytdkww/MJ9T7yPiqwlM8gXSIhqs+v/wBQPWOtQkrfbne9HxUJoudJKZZtxom pSA/c01QEn6u2Xk2rKu4DtrU+TAsBYes1Xr0NoRkjImVWYqEj98upRxGklPpT2GGjrnw7dkaI2BZm gBEjQFkTC1IaoEUHXQkNAk0ygDRmz+4/hUcL8kpAGOPruNuNTULEKsv5WIoupToF5Wc/ulc4wKrPy L/ZsCQmQ==; Received: from [185.62.158.67] (port=63078 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 1nUSms-0004CI-Pd for gcc-patches@gcc.gnu.org; Wed, 16 Mar 2022 08:29:58 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Avoid generating unused labels in genmatch. Date: Wed, 16 Mar 2022 12:29:58 -0000 Message-ID: <001a01d83931$8d6c5ee0$a8451ca0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adg5MUz35K6cX9K5R7W/+wylXwyZkg== 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.4 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch is the second 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 "next_after_fail1:;" label statements in genmatch, if this label is unused/never referenced as the target of a goto. Because jumps to these labels are always forwards, we know at the point the label is emitted whether it is used or not. Because a debugger may set a breakpoint these labels, this increase the size of g{imple,eneric}-match.o in a stage3 build. To save a little extra space, I also shorten the label to "Lfail1:;" and only increment the counter when necessary. This reduces the size of gimple-match.o by 58K 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 (fail_label_used): New global variable. (expr::gen_transform): Set fail_label_used whenever a goto FAIL_LABEL is generated. (dt_simplify::gen_1): Clear fail_label_used when generating a new (provisional) fail_label. Set fail_label used whenever a goto fail_label is generated. Avoid emitting fail_label: if fail_label_used is false, instead decrement fail_label_cnt. Thanks in advance, Roger diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 2eda730..4a61f4e 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -2356,6 +2356,8 @@ capture_info::walk_c_expr (c_expr *e) /* The current label failing the current matched pattern during code generation. */ static char *fail_label; +/* Record that a reference/goto to the above label been generated. */ +static bool fail_label_used; /* Code generation off the decision tree and the refered AST nodes. */ @@ -2533,6 +2535,7 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, fprintf_indent (f, indent, "if (!_r%d) goto %s;\n", depth, fail_label); + fail_label_used = true; if (*opr == CONVERT_EXPR) { indent -= 4; @@ -2560,13 +2563,15 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, fprintf (f, ");\n"); if (opr->kind != id_base::CODE) { - fprintf_indent (f, indent, "if (!_r%d)\n", depth); - fprintf_indent (f, indent, " goto %s;\n", fail_label); + fprintf_indent (f, indent, "if (!_r%d) goto %s;\n", + depth, fail_label); + fail_label_used = true; } if (force_leaf) { fprintf_indent (f, indent, "if (EXPR_P (_r%d))\n", depth); fprintf_indent (f, indent, " goto %s;\n", fail_label); + fail_label_used = true; } if (*opr == CONVERT_EXPR) { @@ -3285,8 +3290,9 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) static unsigned fail_label_cnt; char local_fail_label[256]; - snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_cnt); + snprintf (local_fail_label, 256, "Lfail%u", ++fail_label_cnt); fail_label = local_fail_label; + fail_label_used = false; /* Analyze captures and perform early-outs on the incoming arguments that cover cases we cannot handle. */ @@ -3301,6 +3307,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf_indent (f, indent, "if (TREE_SIDE_EFFECTS (_p%d)) goto %s;\n", i, fail_label); + fail_label_used = true; if (verbose >= 1) warning_at (as_a (s->match)->ops[i]->location, "forcing toplevel operand to have no " @@ -3316,6 +3323,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf_indent (f, indent, "if (TREE_SIDE_EFFECTS (captures[%d])) " "goto %s;\n", i, fail_label); + fail_label_used = true; if (verbose >= 1) warning_at (cinfo.info[i].c->location, "forcing captured operand to have no " @@ -3358,7 +3366,12 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } if (s->kind == simplify::SIMPLIFY) - fprintf_indent (f, indent, "if (__builtin_expect (!dbg_cnt (match), 0)) goto %s;\n", fail_label); + { + fprintf_indent (f, indent, + "if (__builtin_expect (!dbg_cnt (match), 0)) goto %s;\n", + fail_label); + fail_label_used = true; + } fprintf_indent (f, indent, "if (__builtin_expect (dump_file && (dump_flags & TDF_FOLDING), 0)) " "fprintf (dump_file, \"%s ", @@ -3430,9 +3443,12 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf_indent (f, indent, "res_op->resimplify (lseq, valueize);\n"); if (e->force_leaf) - fprintf_indent (f, indent, - "if (!maybe_push_res_to_seq (res_op, NULL)) " - "goto %s;\n", fail_label); + { + fprintf_indent (f, indent, + "if (!maybe_push_res_to_seq (res_op, NULL))" + " goto %s;\n", fail_label); + fail_label_used = true; + } } } else if (result->type == operand::OP_CAPTURE @@ -3488,9 +3504,12 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) continue; if (cinfo.info[i].result_use_count > cinfo.info[i].match_use_count) - fprintf_indent (f, indent, - "if (! tree_invariant_p (captures[%d])) " - "goto %s;\n", i, fail_label); + { + fprintf_indent (f, indent, + "if (! tree_invariant_p (captures[%d]))" + " goto %s;\n", i, fail_label); + fail_label_used = true; + } } for (unsigned j = 0; j < e->ops.length (); ++j) { @@ -3539,8 +3558,9 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf (f, ");\n"); if (!is_a (opr)) { - fprintf_indent (f, indent, "if (!_r)\n"); - fprintf_indent (f, indent, " goto %s;\n", fail_label); + fprintf_indent (f, indent, "if (!_r) goto %s;\n", + fail_label); + fail_label_used = true; } } } @@ -3581,7 +3601,10 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } indent -= 2; fprintf_indent (f, indent, "}\n"); - fprintf (f, "%s:;\n", fail_label); + if (fail_label_used) + fprintf (f, "%s:;\n", fail_label); + else + fail_label_cnt--; fail_label = NULL; }