From: Richard Biener Date: Wed, 23 Feb 2022 12:47:01 +0000 (+0100) Subject: middle-end/109505 - backport match.pd ! support for GENERIC X-Git-Tag: releases/gcc-11.5.0~744 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfa476528ceeac96865a48c49f3f1a15d566d209;p=thirdparty%2Fgcc.git middle-end/109505 - backport match.pd ! support for GENERIC The patch adds support for the ! modifier to GENERIC, backported from r12-7361-gfdc46830f1b793. 2023-06-02 Richard Biener PR tree-optimization/109505 * doc/match-and-simplify.texi: Amend ! documentation. * genmatch.c (expr::gen_transform): Code-generate ! support for GENERIC. (parser::parse_expr): Allow ! for GENERIC. --- diff --git a/gcc/doc/match-and-simplify.texi b/gcc/doc/match-and-simplify.texi index e7e5a4f72995..b76aeac4121e 100644 --- a/gcc/doc/match-and-simplify.texi +++ b/gcc/doc/match-and-simplify.texi @@ -374,8 +374,10 @@ for example which moves the outer @code{plus} operation to the inner arms of the @code{vec_cond} expression but only if the actual plus -operations both simplify. Note this is currently only supported -for code generation targeting @code{GIMPLE}. +operations both simplify. Note that on @code{GENERIC} a simple +operand means that the result satisfies @code{!EXPR_P} which +can be limiting if the operation itself simplifies but the +remaining operand is an (unrelated) expression. As intermediate conversions are often optional there is a way to avoid the need to repeat patterns both with and without such diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 3b99705606cc..e22158665fb3 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -2554,19 +2554,20 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, fprintf_indent (f, indent, "_r%d = fold_build%d_loc (loc, %s, %s", depth, ops.length(), opr_name, type); else - { - fprintf_indent (f, indent, "{\n"); - fprintf_indent (f, indent, " _r%d = maybe_build_call_expr_loc (loc, " - "%s, %s, %d", depth, opr_name, type, ops.length()); - } + fprintf_indent (f, indent, "_r%d = maybe_build_call_expr_loc (loc, " + "%s, %s, %d", depth, opr_name, type, ops.length()); for (unsigned i = 0; i < ops.length (); ++i) fprintf (f, ", _o%d[%u]", depth, i); 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, "}\n"); + fprintf_indent (f, indent, "if (!_r%d)\n", depth); + fprintf_indent (f, indent, " goto %s;\n", fail_label); + } + if (force_leaf) + { + fprintf_indent (f, indent, "if (EXPR_P (_r%d))\n", depth); + fprintf_indent (f, indent, " goto %s;\n", fail_label); } if (*opr == CONVERT_EXPR) { @@ -4300,9 +4301,6 @@ parser::parse_expr () && token->type == CPP_NOT && !(token->flags & PREV_WHITE)) { - if (!gimple) - fatal_at (token, "forcing simplification to a leaf is not supported " - "for GENERIC"); eat_token (CPP_NOT); e->force_leaf = true; }