From patchwork Thu Oct 20 13:58:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1692528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kJydssaC; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MtTjf6F9mz1ygT for ; Fri, 21 Oct 2022 00:59:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ABCA3851173 for ; Thu, 20 Oct 2022 13:59:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ABCA3851173 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666274352; bh=5X3x9PKekKBwKJQdEQBlcw3NPSyGk3iZ8fxJ5jXHT7Q=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kJydssaCh64ay3g0jLwk8w8Zv0G2k+Ar62fcWeAwB3fGbzI860wNMtUj1UdRGPgcN D13ffDbyPmAGNMBlwJ1j7mJC3yAEIZHjbUAX32a4KIrpNmn3Bu0FxxQbPAV68goRzY 24ABd4kcIyNG1mQyx0WcT8qa/PS5R3VemiwmGzbQ= 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 F24A23851168 for ; Thu, 20 Oct 2022 13:58:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F24A23851168 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 BAD3EED1; Thu, 20 Oct 2022 06:58:21 -0700 (PDT) Received: from [10.57.4.196] (unknown [10.57.4.196]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E21323F67D; Thu, 20 Oct 2022 06:58:14 -0700 (PDT) Message-ID: Date: Thu, 20 Oct 2022 14:58:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [PATCH]vect: Fix vectype when widening container type in bitfield pattern [PR107326] X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 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: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Cc: Richard Sandiford , Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, The 'vect_recog_bitfield_ref_pattern' was not correctly adapting the vectype when widening the container. I thought the original tests covered that code-path but they didn't, so I added a new run-test that covers it too. Bootstrapped and regression tested on x86_64 and aarch64. gcc/ChangeLog:     PR tree-optimization/107326     * tree-vect-patterns.cc (vect_recog_bitfield_ref_pattern): Change     vectype when widening container. gcc/testsuite/ChangeLog:     * gcc.dg/vect/pr107326.c: New test.     * gcc.dg/vect/vect-bitfield-read-7.c diff --git a/gcc/testsuite/gcc.dg/vect/pr107326.c b/gcc/testsuite/gcc.dg/vect/pr107326.c new file mode 100644 index 0000000000000000000000000000000000000000..333a515e7410a5b257a9f225b56b14b619af3118 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107326.c @@ -0,0 +1,24 @@ +/* PR107326 */ +/* { dg-do compile } */ +struct Gsymtab { + unsigned int : 8; + unsigned int visited_somewhere : 1; +}; + +extern struct Gsymtab glob_symtab[]; + +int +visit_children (int i) +{ + int numvisited = 0; + + while (i < 1) + { + if (glob_symtab[i].visited_somewhere) + ++numvisited; + + ++i; + } + + return numvisited; +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c b/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c new file mode 100644 index 0000000000000000000000000000000000000000..3b505db2bd3eb6938d2f3b6f7426765333c271a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c @@ -0,0 +1,43 @@ +/* { dg-require-effective-target vect_int } */ + +#include +#include "tree-vect.h" + +extern void abort(void); + +struct s { + unsigned i : 8; + char a : 4; +}; + +#define N 32 +#define ELT0 {0xFUL, 0} +#define ELT1 {0xFUL, 1} +#define ELT2 {0xFUL, 2} +#define ELT3 {0xFUL, 3} +#define RES 48 +struct s A[N] + = { ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3, + ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3, + ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3, + ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3}; + +int __attribute__ ((noipa)) +f(struct s *ptr, unsigned n) { + int res = 0; + for (int i = 0; i < n; ++i) + res += ptr[i].a; + return res; +} + +int main (void) +{ + check_vect (); + + if (f(&A[0], N) != RES) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 6afd57a50c4bcb5aec7ccca6e5dc069caa4a5a30..24673f8d4d92e34706fa6c4ed2cf2ed85d6bb517 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -1922,7 +1922,8 @@ vect_recog_bitfield_ref_pattern (vec_info *vinfo, stmt_vec_info stmt_info, tree ret = gimple_assign_lhs (first_stmt); tree ret_type = TREE_TYPE (ret); bool shift_first = true; - tree vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (container)); + tree container_type = TREE_TYPE (container); + tree vectype = get_vectype_for_scalar_type (vinfo, container_type); /* We move the conversion earlier if the loaded type is smaller than the return type to enable the use of widening loads. */ @@ -1933,15 +1934,15 @@ vect_recog_bitfield_ref_pattern (vec_info *vinfo, stmt_vec_info stmt_info, = gimple_build_assign (vect_recog_temp_ssa_var (ret_type), NOP_EXPR, container); container = gimple_get_lhs (pattern_stmt); - append_pattern_def_seq (vinfo, stmt_info, pattern_stmt); + container_type = TREE_TYPE (container); + vectype = get_vectype_for_scalar_type (vinfo, container_type); + append_pattern_def_seq (vinfo, stmt_info, pattern_stmt, vectype); } else if (!useless_type_conversion_p (TREE_TYPE (container), ret_type)) /* If we are doing the conversion last then also delay the shift as we may be able to combine the shift and conversion in certain cases. */ shift_first = false; - tree container_type = TREE_TYPE (container); - /* If the only use of the result of this BIT_FIELD_REF + CONVERT is a PLUS_EXPR then do the shift last as some targets can combine the shift and add into a single instruction. */