From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id DAC00385801B for ; Fri, 25 Mar 2022 12:15:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DAC00385801B Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C43EB210FC; Fri, 25 Mar 2022 12:15:00 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (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 BEDA4A3B87; Fri, 25 Mar 2022 12:15:00 +0000 (UTC) Date: Fri, 25 Mar 2022 13:15:00 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: Re: [PATCH] middle-end/105049 - fix uniform_vector_p and vector CTOR gimplification Message-ID: <15128pq9-98p-6n1q-855r-3q515071324@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.9 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: , X-List-Received-Date: Fri, 25 Mar 2022 12:15:03 -0000 On Fri, 25 Mar 2022, Richard Biener wrote: > We have > > return VIEW_CONVERT_EXPR( VEC_PERM_EXPR < {<<< Unknown tree: compound_literal_expr > V D.1984 = { 0 }; >>>, { 0 }} , {<<< Unknown tree: compound_literal_expr > V D.1985 = { 0 }; >>>, { 0 }} , { 0, 0 } > & {(short int) SAVE_EXPR , (short int) SAVE_EXPR }); > > where we gimplify the init CTORs to > > _1 = {{ 0 }, { 0 }}; > _2 = {{ 0 }, { 0 }}; > > instead of to vector constants. That later runs into a bug in > uniform_vector_p which doesn't handle CTORs of vector elements > correctly. > > The following adjusts uniform_vector_p to handle CTORs of vector > elements and also makes sure to simplify the CTORs to VECTOR_CSTs > during gimplification by re-ordering the simplification to after > CTOR flag recomputation. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. At this > point I'm leaning towards delaying the gimplification change > to stage1 - do you agree? I have now pushed the variant with just the tree.cc hunk. Richard. > Thanks, > Richard. > > 2022-03-25 Richard Biener > > PR middle-end/105049 > * gimplify.cc (gimplify_init_constructor): First gimplify, > then simplify the result to a VECTOR_CST. > * tree.cc (uniform_vector_p): Recurse for VECTOR_CST or > CONSTRUCTOR first elements. > > * gcc/testsuite/gcc.dg/pr105049.c: New testcase. > --- > gcc/gimplify.cc | 33 ++++++++++++++++----------------- > gcc/testsuite/gcc.dg/pr105049.c | 12 ++++++++++++ > gcc/tree.cc | 2 ++ > 3 files changed, 30 insertions(+), 17 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr105049.c > > diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc > index f62f150fc08..a866d4e6f56 100644 > --- a/gcc/gimplify.cc > +++ b/gcc/gimplify.cc > @@ -5390,6 +5390,22 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > if (notify_temp_creation) > return GS_OK; > > + /* Vector types use CONSTRUCTOR all the way through gimple > + compilation as a general initializer. */ > + FOR_EACH_VEC_SAFE_ELT (elts, ix, ce) > + { > + enum gimplify_status tret; > + tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val, > + fb_rvalue); > + if (tret == GS_ERROR) > + ret = GS_ERROR; > + else if (TREE_STATIC (ctor) > + && !initializer_constant_valid_p (ce->value, > + TREE_TYPE (ce->value))) > + TREE_STATIC (ctor) = 0; > + } > + recompute_constructor_flags (ctor); > + > /* Go ahead and simplify constant constructors to VECTOR_CST. */ > if (TREE_CONSTANT (ctor)) > { > @@ -5412,25 +5428,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > TREE_OPERAND (*expr_p, 1) = build_vector_from_ctor (type, elts); > break; > } > - > - TREE_CONSTANT (ctor) = 0; > } > > - /* Vector types use CONSTRUCTOR all the way through gimple > - compilation as a general initializer. */ > - FOR_EACH_VEC_SAFE_ELT (elts, ix, ce) > - { > - enum gimplify_status tret; > - tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val, > - fb_rvalue); > - if (tret == GS_ERROR) > - ret = GS_ERROR; > - else if (TREE_STATIC (ctor) > - && !initializer_constant_valid_p (ce->value, > - TREE_TYPE (ce->value))) > - TREE_STATIC (ctor) = 0; > - } > - recompute_constructor_flags (ctor); > if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0))) > TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p); > } > diff --git a/gcc/testsuite/gcc.dg/pr105049.c b/gcc/testsuite/gcc.dg/pr105049.c > new file mode 100644 > index 00000000000..b0518c6a181 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr105049.c > @@ -0,0 +1,12 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -fno-tree-forwprop" } */ > + > +typedef short __attribute__((__vector_size__ (sizeof(short)))) V; > +typedef short __attribute__((__vector_size__ (2*sizeof(short)))) U; > +char c; > + > +U > +foo (void) > +{ > + return __builtin_shufflevector ((V){}, (V){}, 0, 0) & c; > +} > diff --git a/gcc/tree.cc b/gcc/tree.cc > index b8017af6cfc..ec200e9a7eb 100644 > --- a/gcc/tree.cc > +++ b/gcc/tree.cc > @@ -10266,6 +10266,8 @@ uniform_vector_p (const_tree vec) > if (i != nelts) > return NULL_TREE; > > + if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST) > + return uniform_vector_p (first); > return first; > } > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)