From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 6C3063858018; Tue, 9 Nov 2021 13:05:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C3063858018 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10260] tree-optimization/100253 - fix bogus aligned vectorized loads/stores X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 91a66770873d51f31346de3e173ee7a8b3f6e86a X-Git-Newrev: 92ffe7c3b6ffee8fd6ef92a5b3b4cc09263b01ee Message-Id: <20211109130552.6C3063858018@sourceware.org> Date: Tue, 9 Nov 2021 13:05:52 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 13:05:52 -0000 https://gcc.gnu.org/g:92ffe7c3b6ffee8fd6ef92a5b3b4cc09263b01ee commit r10-10260-g92ffe7c3b6ffee8fd6ef92a5b3b4cc09263b01ee Author: Richard Biener Date: Thu Apr 29 11:52:08 2021 +0200 tree-optimization/100253 - fix bogus aligned vectorized loads/stores 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. 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. Diff: --- gcc/testsuite/g++.dg/pr100253.C | 33 +++++++++++++++++++++++++++++++++ gcc/tree-vect-stmts.c | 16 ++++------------ 2 files changed, 37 insertions(+), 12 deletions(-) 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 6418edb5204..2ef71ec41c0 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -8368,6 +8368,7 @@ vectorizable_store (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, && 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) { @@ -8389,7 +8390,6 @@ vectorizable_store (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, /* 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, @@ -8408,14 +8408,10 @@ vectorizable_store (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, : 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)); gassign *new_stmt = gimple_build_assign (data_ref, vec_oprnd); @@ -9567,10 +9563,10 @@ vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, && 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 @@ -9621,14 +9617,10 @@ vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, = 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,