From patchwork Wed Aug 5 10:04:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1341181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de 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 ozlabs.org (Postfix) with ESMTPS id 4BM6fY4lnxz9sPB for ; Wed, 5 Aug 2020 20:04:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FCDF3857C60; Wed, 5 Aug 2020 10:04:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 7718D3857C47 for ; Wed, 5 Aug 2020 10:04:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7718D3857C47 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DF7B5AEF8 for ; Wed, 5 Aug 2020 10:04:29 +0000 (UTC) Date: Wed, 5 Aug 2020 12:04:13 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Make genmatch transform failure handling more consistent Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Currently whether a fail during the transform stage is fatal or whether following patterns are still considers is a bit random depending on whether the pattern is wrapped in a for for example. The follwing makes it consistent by replacing early returns with gotos to the end of the pattern processing. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2020-08-05 Richard Biener * genmatch.c (fail_label): New global. (expr::gen_transform): Branch to fail_label instead of returning. Fix indent of call argument checking. (dt_simplify::gen_1): Compute and emit fail_label, branch to it instead of returning early. --- gcc/genmatch.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 4e13bc51579..107f6f2ec9e 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -2352,6 +2352,10 @@ capture_info::walk_c_expr (c_expr *e) } +/* The current label failing the current matched pattern during + code generation. */ +static char *fail_label; + /* Code generation off the decision tree and the refered AST nodes. */ bool @@ -2527,8 +2531,8 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, "_r%d = maybe_push_res_to_seq (&tem_op, %s);\n", depth, !force_leaf ? "lseq" : "NULL"); fprintf_indent (f, indent, - "if (!_r%d) return false;\n", - depth); + "if (!_r%d) goto %s;\n", + depth, fail_label); if (*opr == CONVERT_EXPR) { indent -= 4; @@ -2560,7 +2564,7 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, if (opr->kind != id_base::CODE) { fprintf_indent (f, indent, " if (!_r%d)\n", depth); - fprintf_indent (f, indent, " return NULL_TREE;\n"); + fprintf_indent (f, indent, " goto %s;\n", fail_label); fprintf_indent (f, indent, "}\n"); } if (*opr == CONVERT_EXPR) @@ -3068,12 +3072,12 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, /* We need to be defensive against bogus prototypes allowing calls with not enough arguments. */ fprintf_indent (f, indent, - " if (gimple_call_num_args (_c%d) == %d)\n" - " {\n", depth, e->ops.length ()); + " if (gimple_call_num_args (_c%d) == %d)\n", + depth, e->ops.length ()); + fprintf_indent (f, indent, " {\n"); fns[i]->gen (f, indent + 6, true, depth); - fprintf_indent (f, indent, - " }\n" - " break;\n"); + fprintf_indent (f, indent, " }\n"); + fprintf_indent (f, indent, " break;\n"); } fprintf_indent (f, indent, "default:;\n"); @@ -3278,6 +3282,11 @@ 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); + fail_label = local_fail_label; + /* Analyze captures and perform early-outs on the incoming arguments that cover cases we cannot handle. */ capture_info cinfo (s, result, gimple); @@ -3289,8 +3298,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) if (cinfo.force_no_side_effects & (1 << i)) { fprintf_indent (f, indent, - "if (TREE_SIDE_EFFECTS (_p%d)) return NULL_TREE;\n", - i); + "if (TREE_SIDE_EFFECTS (_p%d)) goto %s;\n", + i, fail_label); if (verbose >= 1) warning_at (as_a (s->match)->ops[i]->location, "forcing toplevel operand to have no " @@ -3305,7 +3314,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) { fprintf_indent (f, indent, "if (TREE_SIDE_EFFECTS (captures[%d])) " - "return NULL_TREE;\n", i); + "goto %s;\n", i, fail_label); if (verbose >= 1) warning_at (cinfo.info[i].c->location, "forcing captured operand to have no " @@ -3348,8 +3357,7 @@ 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)) return %s;\n", - gimple ? "false" : "NULL_TREE"); + fprintf_indent (f, indent, "if (__builtin_expect (!dbg_cnt (match), 0)) goto %s;\n", fail_label); fprintf_indent (f, indent, "if (__builtin_expect (dump_file && (dump_flags & TDF_FOLDING), 0)) " "fprintf (dump_file, \"%s ", @@ -3361,6 +3369,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) true); fprintf (f, ", __FILE__, __LINE__);\n"); + fprintf_indent (f, indent, "{\n"); + indent += 2; if (!result) { /* If there is no result then this is a predicate implementation. */ @@ -3474,7 +3484,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) > cinfo.info[i].match_use_count) fprintf_indent (f, indent, "if (! tree_invariant_p (captures[%d])) " - "return NULL_TREE;\n", i); + "goto %s;\n", i, fail_label); } for (unsigned j = 0; j < e->ops.length (); ++j) { @@ -3524,7 +3534,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) if (!is_a (opr)) { fprintf_indent (f, indent, "if (!_r)\n"); - fprintf_indent (f, indent, " return NULL_TREE;\n"); + fprintf_indent (f, indent, " goto %s;\n", fail_label); } } } @@ -3563,6 +3573,10 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf_indent (f, indent, "return _r;\n"); } } + indent -= 2; + fprintf_indent (f, indent, "}\n"); + fprintf (f, "%s:;\n", fail_label); + fail_label = NULL; } /* Generate code for the '(if ...)', '(with ..)' and actual transform