From patchwork Mon Jul 6 14:31:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1323653 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=suse.de 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 4B0p1353Cjz9sQt for ; Tue, 7 Jul 2020 00:31:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E0763857C7C; Mon, 6 Jul 2020 14:31:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 8627C3858D35 for ; Mon, 6 Jul 2020 14:31:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8627C3858D35 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 EBF9BADAA for ; Mon, 6 Jul 2020 14:31:45 +0000 (UTC) Date: Mon, 6 Jul 2020 16:31:45 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/96075 - fix bogus misalignment calculation Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This fixes bogus misalignment calculation for negative steps since an assertion a previous comment indicated no longer holds: /* DR_STEP(dr) is the same as -TYPE_SIZE of the scalar type, otherwise we wouldn't be here. */ Thus the following replaces DR_STEP by -TYPE_SIZE. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk sofar. Richard. 2020-07-06 Richard Biener PR tree-optimization/96075 * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Use TYPE_SIZE_UNIT of the vector component type instead of DR_STEP for the misalignment calculation for negative step. * gcc.dg/vect/slp-46.c: New testcase. --- gcc/testsuite/gcc.dg/vect/slp-46.c | 96 ++++++++++++++++++++++++++++++ gcc/tree-vect-data-refs.c | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/slp-46.c diff --git a/gcc/testsuite/gcc.dg/vect/slp-46.c b/gcc/testsuite/gcc.dg/vect/slp-46.c new file mode 100644 index 00000000000..17dfa285ec1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/slp-46.c @@ -0,0 +1,96 @@ +/* { dg-require-effective-target vect_double } */ + +#include "tree-vect.h" + +double x[1024], y[1024]; + +void __attribute__((noipa)) foo() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = y[i]; + x[2*i+1] = y[i]; + } +} + +void __attribute__((noipa)) bar() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = y[2*i]; + x[2*i+1] = y[2*i]; + } +} + +void __attribute__((noipa)) baz() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = y[511-i]; + x[2*i+1] = y[511-i]; + } +} + +void __attribute__((noipa)) boo() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = y[2*(511-i)]; + x[2*i+1] = y[2*(511-i)]; + } +} + +int +main () +{ + check_vect (); + + for (int i = 0; i < 1024; ++i) + { + x[i] = 0; + y[i] = i; + __asm__ volatile (""); + } + + foo (); + for (int i = 0; i < 1024; ++i) + if (x[i] != y[i/2]) + abort (); + + for (int i = 0; i < 1024; ++i) + { + x[i] = 0; + __asm__ volatile (""); + } + + bar (); + for (int i = 0; i < 1024; ++i) + if (x[i] != y[2*(i/2)]) + abort (); + + for (int i = 0; i < 1024; ++i) + { + x[i] = 0; + __asm__ volatile (""); + } + + baz (); + for (int i = 0; i < 1024; ++i) + if (x[i] != y[511 - i/2]) + abort (); + + for (int i = 0; i < 1024; ++i) + { + x[i] = 0; + __asm__ volatile (""); + } + + boo (); + for (int i = 0; i < 1024; ++i) + if (x[i] != y[2*(511 - i/2)]) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" } } */ diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 2462276e7c2..959c2d3378f 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -1109,7 +1109,7 @@ vect_compute_data_ref_alignment (vec_info *vinfo, dr_vec_info *dr_info) if (tree_int_cst_sgn (drb->step) < 0) /* PLUS because STEP is negative. */ misalignment += ((TYPE_VECTOR_SUBPARTS (vectype) - 1) - * TREE_INT_CST_LOW (drb->step)); + * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype)))); unsigned int const_misalignment; if (!known_misalignment (misalignment, vect_align_c, &const_misalignment))