From patchwork Fri Mar 25 09:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 52345 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB4163840C05 for ; Fri, 25 Mar 2022 09:52:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB4163840C05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648201948; bh=fzFBapIHul0GE7FkYb/CUMgN8ILzEB6FrEf/3gdxJw4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=N+6LuNMn2GPHm/Xhk+gT1OttRb9CLiv4Fxb+61P0A/0KNmXNF1C+bDwbSFrLj4Y4J M2JGInfOFGIpVwNjnIxmnctOgYWvl3pgFoFjVuNRyVrKcbD8ftcrcYXCn8UYlW/bAC m6UDdcqikkV+rgSX/vm7YJefcDVKPUFMLMomxVuI= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 915EC3858C2C for ; Fri, 25 Mar 2022 09:51:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 915EC3858C2C 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 640941F38D; Fri, 25 Mar 2022 09:51:58 +0000 (UTC) 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 4B21B132E9; Fri, 25 Mar 2022 09:51:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id r40mEb6QPWIVDAAAMHmgww (envelope-from ); Fri, 25 Mar 2022 09:51:58 +0000 Date: Fri, 25 Mar 2022 10:51:57 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/105049 - fix uniform_vector_p and vector CTOR gimplification MIME-Version: 1.0 Message-Id: <20220325095158.4B21B132E9@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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? 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; }