From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id C4DB23958C0F for ; Thu, 29 Apr 2021 10:42:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4DB23958C0F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BCDAAB007; Thu, 29 Apr 2021 10:42:02 +0000 (UTC) Date: Thu, 29 Apr 2021 12:42:02 +0200 (CEST) From: Richard Biener Sender: rguenther@ryzen.fritz.box To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com Subject: [PATCH] tree-optimization/100253 - fix bogus aligned vectorized loads/stores Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-List-Received-Date: Thu, 29 Apr 2021 10:42:05 -0000 At some point DR_MISALIGNMENT was supposed to be -1 when the access was not element aligned. That's obviously not true at this point so this adjusts both store and load vectorizing to no longer assume this which in turn allows simplifying the code. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk sofar. 2021-04-29 Richard Biener PR tree-optimization/100253 * tree-vect-stmts.c (vectorizable_load): Do not assume element alignment when DR_MISALIGNMENT is -1. (vectorizable_store): Likewise. * g++.dg/pr100253.C: New testcase. --- gcc/testsuite/g++.dg/pr100253.C | 33 +++++++++++++++++++++++++++++++++ gcc/tree-vect-stmts.c | 18 ++++-------------- 2 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr100253.C diff --git a/gcc/testsuite/g++.dg/pr100253.C b/gcc/testsuite/g++.dg/pr100253.C new file mode 100644 index 00000000000..0102caa7df8 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr100253.C @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-tree-bit-ccp -ftree-slp-vectorize" } */ + +#include + +struct T +{ +}; + +struct S +{ + std::vector < std::vector < T > > v; + char x; + char y[16]; + char z[16]; +}; + +S s, g[1]; + +void +foo (char *buf) +{ + s = g[*buf]; +} + +char c; + +int +main () +{ + foo (&c); + return 0; +} diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 4c01e82ff39..bd2a1c89e67 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -8166,6 +8166,7 @@ vectorizable_store (vec_info *vinfo, && TREE_CODE (dataref_ptr) == SSA_NAME) set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, misalign); + align = least_bit_hwi (misalign | align); if (memory_access_type == VMAT_CONTIGUOUS_REVERSE) { @@ -8187,7 +8188,6 @@ vectorizable_store (vec_info *vinfo, /* Arguments are ready. Create the new vector stmt. */ if (final_mask) { - align = least_bit_hwi (misalign | align); tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT); gcall *call = gimple_build_call_internal (IFN_MASK_STORE, 4, @@ -8202,7 +8202,6 @@ vectorizable_store (vec_info *vinfo, tree final_len = vect_get_loop_len (loop_vinfo, loop_lens, vec_num * ncopies, vec_num * j + i); - align = least_bit_hwi (misalign | align); tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT); machine_mode vmode = TYPE_MODE (vectype); opt_machine_mode new_ovmode @@ -8241,14 +8240,10 @@ vectorizable_store (vec_info *vinfo, : build_int_cst (ref_type, 0)); if (aligned_access_p (first_dr_info)) ; - else if (DR_MISALIGNMENT (first_dr_info) == -1) - TREE_TYPE (data_ref) - = build_aligned_type (TREE_TYPE (data_ref), - align * BITS_PER_UNIT); else TREE_TYPE (data_ref) = build_aligned_type (TREE_TYPE (data_ref), - TYPE_ALIGN (elem_type)); + align * BITS_PER_UNIT); vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr)); new_stmt = gimple_build_assign (data_ref, vec_oprnd); vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi); @@ -9452,10 +9447,10 @@ vectorizable_load (vec_info *vinfo, && TREE_CODE (dataref_ptr) == SSA_NAME) set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, misalign); + align = least_bit_hwi (misalign | align); if (final_mask) { - align = least_bit_hwi (misalign | align); tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT); gcall *call @@ -9472,7 +9467,6 @@ vectorizable_load (vec_info *vinfo, = vect_get_loop_len (loop_vinfo, loop_lens, vec_num * ncopies, vec_num * j + i); - align = least_bit_hwi (misalign | align); tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT); gcall *call @@ -9548,14 +9542,10 @@ vectorizable_load (vec_info *vinfo, = fold_build2 (MEM_REF, ltype, dataref_ptr, offset); if (alignment_support_scheme == dr_aligned) ; - else if (DR_MISALIGNMENT (first_dr_info) == -1) - TREE_TYPE (data_ref) - = build_aligned_type (TREE_TYPE (data_ref), - align * BITS_PER_UNIT); else TREE_TYPE (data_ref) = build_aligned_type (TREE_TYPE (data_ref), - TYPE_ALIGN (elem_type)); + align * BITS_PER_UNIT); if (ltype != vectype) { vect_copy_ref_info (data_ref, -- 2.26.2