From patchwork Tue Mar 28 11:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 76007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2141334vqo; Tue, 28 Mar 2023 04:31:26 -0700 (PDT) X-Google-Smtp-Source: AKy350axOjPMcJRQDogx7rDphqykHnSytilSEncQZt53yb1dJxjwiL7mOKGO5kCUbVNs/ArUx1H8 X-Received: by 2002:a17:907:97c9:b0:933:80c:67d7 with SMTP id js9-20020a17090797c900b00933080c67d7mr18616912ejc.49.1680003086857; Tue, 28 Mar 2023 04:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680003086; cv=none; d=google.com; s=arc-20160816; b=ptGHrnQrCgnXZau2LuRaduDKKQe9nz2//vReJufbtKRu23RE32Pr5hnphsHgCxn+Ak 6axwOSR9iwIbhub8WhDlSI1yDsDwuehIY/Mqhg3tZO8tmQfNw5AIMd48dEo3W9NCMH6+ 189YFaVVM4iW0jcs6tlTVhYHxJMbEGcfsOIPLZxoRoblBJ62VHJ2R3ERZNOrFFYMP+6+ bvYpGuTdpoUO5wyU2+hgIaJvNazzwDjhrJ1bfFqiq2/hEoWqimEQRm07nNlO6mG3EY+a iugJwrcHkjlijBP3942rdEnNlYCMraV2W7ESLohHY7VegyraqWJBwBAa0CmPpu3rpt/O pcYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=nRZyAqUsRL1+FDunJshl0ZFKdVuyfx9IqMpfkAoBI48=; b=C+3rfCrD7aAifTvE0dLyesTd1DqFZFSc8iPp+kNMJZIl+UhTUn8NvCP19c7rErXT7v 7uTld0GeFnRXJwnotQaTIzvD0G9j9HW3gCEvsrhAR4kpLNbbJh2WYVb8mOCBvd74KMOM n9mzrC2xVzl01qgBR85UgXRTC1iygaVbVWmXAJJr82iPq0URRTMWxhJ5Yg01O0aDzL0i 5s6OOv0zN1WmPGCphGF3BK5I3qPi6/1Jmx5pt1Gc/bsi59O/Bk276iTK3GCnsUG/wzgv BBGc+bAyo9jBv07X/Z6VSDW7z2RkJDJW7T8Tyl3XzyUzgoN7m+Vf0g56AczGEDe1gkw3 aAfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lm5WKgSZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e3-20020a50fb83000000b004ad7203a2c6si32321823edq.230.2023.03.28.04.31.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 04:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lm5WKgSZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C77EE3857C5A for ; Tue, 28 Mar 2023 11:31:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C77EE3857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680003083; bh=nRZyAqUsRL1+FDunJshl0ZFKdVuyfx9IqMpfkAoBI48=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lm5WKgSZKaftQEDZMbZISk5kUyuHfuIbCReWkHlEIZz46228LN7zhFwLtPpZ5fPie GA0DXoJ4AoeWYDNRXAkZ/3u+xVNW8+bluywSz8ArXT3w+ujk8es1osUYRWffscwF5h bNCuJc4ncmy28Sp0zkgaoKCM19MeG9QF8KvPfTis= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 794EE3858D39 for ; Tue, 28 Mar 2023 11:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 794EE3858D39 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 973FF1FD72 for ; Tue, 28 Mar 2023 11:30:38 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 822D42C141 for ; Tue, 28 Mar 2023 11:30:38 +0000 (UTC) Date: Tue, 28 Mar 2023 11:30:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] bootstrap/84402 - improve (match ...) code generation User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230328113123.C77EE3857C5A@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761610916548013611?= X-GMAIL-MSGID: =?utf-8?q?1761610916548013611?= The following avoids duplicating matching code for (match ...) in match.pd when possible. That's more easily possible for (match ...) than simplify because we do not need to handle common matches (those would be diagnosed only during compiling) nor is the result able to inspect the active operator. Specifically this reduces the size of the generated matches for the atomic ops as noted in PR108129. gimple-match.cc shrinks from 245k lines to 209k lines with this patch. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. Richard. PR bootstrap/84402 PR tree-optimization/108129 * genmatch.cc (lower_for): For (match ...) delay substituting into the match operator if possible. (dt_operand::gen_gimple_expr): For user_id look at the first substitute for determining how to access operands. (dt_operand::gen_generic_expr): Likewise. (dt_node::gen_kids): Properly sort user_ids according to their substitutes. (dt_node::gen_kids_1): Code-generate user_id matching. --- gcc/genmatch.cc | 65 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 43bd0212d0e..4fab4135347 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -1464,7 +1464,7 @@ lower_for (simplify *sin, vec& simplifiers) vec& ids = for_vec[fi]; unsigned n_ids = ids.length (); unsigned max_n_opers = 0; - bool can_delay_subst = (sin->kind == simplify::SIMPLIFY); + bool can_delay_subst = true; for (unsigned i = 0; i < n_ids; ++i) { if (ids[i]->substitutes.length () > max_n_opers) @@ -1504,6 +1504,9 @@ lower_for (simplify *sin, vec& simplifiers) else can_delay_subst = false; } + if (sin->kind == simplify::MATCH + && can_delay_subst) + continue; unsigned worklist_end = worklist.length (); for (unsigned si = worklist_start; si < worklist_end; ++si) @@ -1527,7 +1530,9 @@ lower_for (simplify *sin, vec& simplifiers) break; } subst.quick_push (std::make_pair (id, oper)); - match_op = replace_id (match_op, id, oper); + if (sin->kind == simplify::SIMPLIFY + || !can_delay_subst) + match_op = replace_id (match_op, id, oper); if (result_op && !can_delay_subst) result_op = replace_id (result_op, id, oper); @@ -2824,6 +2829,9 @@ dt_operand::gen_gimple_expr (FILE *f, int indent, int depth) unsigned n_ops = e->ops.length (); unsigned n_braces = 0; + if (user_id *u = dyn_cast (id)) + id = u->substitutes[0]; + for (unsigned i = 0; i < n_ops; ++i) { char child_opname[20]; @@ -2905,14 +2913,18 @@ unsigned dt_operand::gen_generic_expr (FILE *f, int indent, const char *opname) { expr *e = static_cast (op); + id_base *id = e->operation; unsigned n_ops = e->ops.length (); + if (user_id *u = dyn_cast (id)) + id = u->substitutes[0]; + for (unsigned i = 0; i < n_ops; ++i) { char child_opname[20]; gen_opname (child_opname, i); - if (e->operation->kind == id_base::CODE) + if (id->kind == id_base::CODE) fprintf_indent (f, indent, "tree %s = TREE_OPERAND (%s, %u);\n", child_opname, opname, i); else @@ -2964,10 +2976,21 @@ dt_node::gen_kids (FILE *f, int indent, bool gimple, int depth) preds.safe_push (op); else { - if (gimple && !e->is_generic) - gimple_exprs.safe_push (op); + user_id *u = dyn_cast (e->operation); + if (u && u->substitutes[0]->kind == id_base::FN) + { + if (gimple) + fns.safe_push (op); + else + generic_fns.safe_push (op); + } else - generic_exprs.safe_push (op); + { + if (gimple && !e->is_generic) + gimple_exprs.safe_push (op); + else + generic_exprs.safe_push (op); + } } } else if (op->op->type == operand::OP_PREDICATE) @@ -3064,11 +3087,19 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, for (unsigned i = 0; i < exprs_len; ++i) { expr *e = as_a (gimple_exprs[i]->op); - id_base *op = e->operation; - if (*op == CONVERT_EXPR || *op == NOP_EXPR) - fprintf_indent (f, indent, "CASE_CONVERT:\n"); + if (user_id *u = dyn_cast (e->operation)) + { + for (auto id : u->substitutes) + fprintf_indent (f, indent, "case %s:\n", id->id); + } else - fprintf_indent (f, indent, "case %s:\n", op->id); + { + id_base *op = e->operation; + if (*op == CONVERT_EXPR || *op == NOP_EXPR) + fprintf_indent (f, indent, "CASE_CONVERT:\n"); + else + fprintf_indent (f, indent, "case %s:\n", op->id); + } fprintf_indent (f, indent, " {\n"); gimple_exprs[i]->gen (f, indent + 4, true, depth); fprintf_indent (f, indent, " break;\n"); @@ -3093,7 +3124,11 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, for (unsigned i = 0; i < fns_len; ++i) { expr *e = as_a (fns[i]->op); - fprintf_indent (f, indent, "case %s:\n", e->operation->id); + if (user_id *u = dyn_cast (e->operation)) + for (auto id : u->substitutes) + fprintf_indent (f, indent, "case %s:\n", id->id); + else + fprintf_indent (f, indent, "case %s:\n", e->operation->id); /* We need to be defensive against bogus prototypes allowing calls with not enough arguments. */ fprintf_indent (f, indent, @@ -3140,7 +3175,13 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth, /* Already handled above. */ continue; else - fprintf_indent (f, indent, "case %s:\n", op->id); + { + if (user_id *u = dyn_cast (op)) + for (auto id : u->substitutes) + fprintf_indent (f, indent, "case %s:\n", id->id); + else + 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");