From patchwork Thu Mar 19 06:51:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1258112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jkj83d55z9sPk for ; Thu, 19 Mar 2020 22:10:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 183DC385E824; Thu, 19 Mar 2020 11:10:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 7B4D4385C017 for ; Thu, 19 Mar 2020 11:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7B4D4385C017 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=richard.sandiford@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 20A25FEC for ; Thu, 19 Mar 2020 04:10:26 -0700 (PDT) Received: from localhost (unknown [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1841C3F9E6 for ; Wed, 18 Mar 2020 23:55:35 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] c-family: Tighten vector handling in type_for_mode [PR94072] Date: Thu, 19 Mar 2020 06:51:22 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-25.0 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In this PR we had a 512-bit VECTOR_TYPE whose mode is XImode (an integer mode used for four 128-bit vectors). When trying to expand a zero constant for it, we hit code in expand_expr_real_1 that tries to use the associated integer type instead. The code used type_for_mode (XImode, 1) to get this integer type. However, the c-family implementation of type_for_mode checks for any registered built-in type that matches the mode and has the right signedness. This meant that it could return a built-in vector type when given an integer mode (particularly if, as here, the vector type isn't supported by the current subtarget and so TYPE_MODE != TYPE_MODE_RAW). The expand code would then cycle endlessly trying to use this "new" type instead of the original vector type. The search loop is probably too lax in other ways -- e.g. it could return records that just happen to have the right mode -- but this seems like a safe, incremental improvement. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2020-03-18 Richard Sandiford gcc/c-family/ PR middle-end/94072 * c-common.c (c_common_type_for_mode): Before using a registered built-in type, check that the vectorness of the type matches the vectorness of the mode. gcc/testsuite/ PR middle-end/94072 * gcc.target/aarch64/pr94072.c: New test. --- gcc/c-family/c-common.c | 11 +++++++---- gcc/testsuite/gcc.target/aarch64/pr94072.c | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr94072.c diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 25020bf1415..8e5a9243827 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2387,10 +2387,13 @@ c_common_type_for_mode (machine_mode mode, int unsignedp) } for (t = registered_builtin_types; t; t = TREE_CHAIN (t)) - if (TYPE_MODE (TREE_VALUE (t)) == mode - && !!unsignedp == !!TYPE_UNSIGNED (TREE_VALUE (t))) - return TREE_VALUE (t); - + { + tree type = TREE_VALUE (t); + if (TYPE_MODE (type) == mode + && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode) + && !!unsignedp == !!TYPE_UNSIGNED (type)) + return type; + } return NULL_TREE; } diff --git a/gcc/testsuite/gcc.target/aarch64/pr94072.c b/gcc/testsuite/gcc.target/aarch64/pr94072.c new file mode 100644 index 00000000000..2aa72eb7a16 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr94072.c @@ -0,0 +1,9 @@ +/* { dg-options "-msve-vector-bits=512" } */ + +#pragma GCC target "+nosve" + +void +foo (void) +{ + (int __attribute__ ((__vector_size__ (64)))){}; +}