From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 95D3A395252F for ; Sun, 11 Dec 2022 13:32:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 95D3A395252F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 800571FE44 for ; Sun, 11 Dec 2022 13:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670765554; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=h2Y7FsifJ4XrzeKFt93dtMtbK7hYwKN8PmrQTzG+adI=; b=xrnZgXQZx+I3Ia0eetPDSQx3qiecVHphPs/lMbN1dzlIGPqCQ6DufBDNjn8WZGJFxYigeW hRsD8IddEaQrzBpJeUqfR/kMr+zYLF/zTdTEvQ5iSGeFcmSVujGmde0nHUUJDBJHV86Skm UJLyZ2eQTLV6GXouxBgmdzX6CbSzJf0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670765554; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=h2Y7FsifJ4XrzeKFt93dtMtbK7hYwKN8PmrQTzG+adI=; b=DD+xPkhb5IoKDEzPfQzWjlGTqefdgmQweVjDRoU0wM4sI4fT2d1gT8r2ObqsoAHR3HwpYz ahC+0x6yriwFlWBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 64ABB13413 for ; Sun, 11 Dec 2022 13:32:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uWOZF/LblWOZKAAAMHmgww (envelope-from ) for ; Sun, 11 Dec 2022 13:32:34 +0000 Date: Sun, 11 Dec 2022 14:32:34 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] Treat ADDR_EXPR and CONSTRUCTOR as GIMPLE/GENERIC magically MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20221211133234.64ABB13413@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The following allows to match ADDR_EXPR for both the invariant &a.b case as well as the &p->d case in a separate definition transparently. This also allows to remove the hack we employ for CONSTRUCTOR which we handle for example with (match vec_same_elem_p CONSTRUCTOR@0 (if (TREE_CODE (@0) == SSA_NAME && uniform_vector_p (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)))))) Note CONSTUCTORs always appear as separate definition in GIMPLE, but I continue to play safe and ADDR_EXPRs are now matched in both places where previously ADDR_EXPR@0 would have missed the &p->x case. This is a prerequesite for the PR89317 fix. Bootstrapped and tested on x86_64-unknown-linux-gnu, will push after testing of the 2nd patch succeeded. * genmatch.cc (dt_node::gen_kids): Handle ADDR_EXPR in both the GENERIC and GIMPLE op position. (dt_simplify::gen): Capture both GENERIC and GIMPLE op position for ADDR_EXPR and CONSTRUCTOR. * match.pd: Simplify CONSTRUCTOR leaf handling. * gcc.dg/tree-ssa/forwprop-3.c: Adjust. * g++.dg/tree-ssa/pr31146-2.C: Likewise. --- gcc/genmatch.cc | 30 ++++++++++++++++++---- gcc/match.pd | 12 +++------ gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C | 2 +- gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 4a8802469cd..f53e61a4a8d 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -2927,8 +2927,16 @@ dt_node::gen_kids (FILE *f, int indent, bool gimple, int depth) if (expr *e = dyn_cast (op->op)) { if (e->ops.length () == 0 + /* In GIMPLE a CONSTRUCTOR always appears in a + separate definition. */ && (!gimple || !(*e->operation == CONSTRUCTOR))) - generic_exprs.safe_push (op); + { + generic_exprs.safe_push (op); + /* But ADDR_EXPRs can appear directly when invariant + and in a separate definition when not. */ + if (gimple && *e->operation == ADDR_EXPR) + gimple_exprs.safe_push (op); + } else if (e->operation->kind == id_base::FN) { if (gimple) @@ -3599,14 +3607,26 @@ dt_simplify::gen (FILE *f, int indent, bool gimple, int depth ATTRIBUTE_UNUSED) if (s->capture_max >= 0) { char opname[20]; - fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = { %s", - s->capture_max + 1, indexes[0]->get_name (opname)); + fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = {", + s->capture_max + 1); - for (int i = 1; i <= s->capture_max; ++i) + for (int i = 0; i <= s->capture_max; ++i) { if (!indexes[i]) break; - fprintf (f, ", %s", indexes[i]->get_name (opname)); + const char *opstr = indexes[i]->get_name (opname); + expr *e = dyn_cast (indexes[i]->op); + fputs (i == 0 ? " " : ", ", f); + if (e && gimple + /* Transparently handle picking up CONSTRUCTOR and ADDR_EXPR + leafs if they appear in a separate definition. */ + && (*e->operation == CONSTRUCTOR + || *e->operation == ADDR_EXPR)) + fprintf (f, "(TREE_CODE (%s) == SSA_NAME " + "? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (%s)) : %s)", + opstr, opstr, opstr); + else + fprintf (f, "%s", opstr); } fprintf (f, " };\n"); } diff --git a/gcc/match.pd b/gcc/match.pd index 127cef9a610..046ea2cdef4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3925,8 +3925,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (view_convert CONSTRUCTOR@0) (with - { tree ctor = (TREE_CODE (@0) == SSA_NAME - ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); } + { tree ctor = @0; } (switch (if (CONSTRUCTOR_NELTS (ctor) == 0) { build_zero_cst (type); }) @@ -7292,8 +7291,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0)))))))) (with { - tree ctor = (TREE_CODE (@0) == SSA_NAME - ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); + tree ctor = @0; tree eltype = TREE_TYPE (TREE_TYPE (ctor)); unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype)); unsigned HOST_WIDE_INT n = tree_to_uhwi (@1); @@ -7941,8 +7939,7 @@ and, /* Fold reduction of a single nonzero element constructor. */ (for reduc (IFN_REDUC_PLUS IFN_REDUC_IOR IFN_REDUC_XOR) (simplify (reduc (CONSTRUCTOR@0)) - (with { tree ctor = (TREE_CODE (@0) == SSA_NAME - ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); + (with { tree ctor = @0; tree elt = ctor_single_nonzero_element (ctor); } (if (elt && !HONOR_SNANS (type) @@ -8161,8 +8158,7 @@ and, (match vec_same_elem_p CONSTRUCTOR@0 - (if (TREE_CODE (@0) == SSA_NAME - && uniform_vector_p (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)))))) + (if (uniform_vector_p (@0)))) (match vec_same_elem_p @0 diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C b/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C index fc268578f69..10232855e26 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C @@ -21,4 +21,4 @@ double foo (void) } /* GCC 8 emits operator new () != NULL with -fcheck-new. */ -/* { dg-final { scan-tree-dump "Replaced .* != 0B. with .1" "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times " != 0B\\)" 1 "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c index 4aa68c64950..bfdfba1800c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c @@ -14,4 +14,4 @@ int foo(struct bar *x) return 0; } -/* { dg-final { scan-tree-dump "Replaced .p_. < q_.. with .1." "forwprop1" } } */ +/* { dg-final { scan-tree-dump "return 1;" "forwprop1" } } */ -- 2.35.3