From patchwork Thu Nov 5 13:26:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 540424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3152C1402B6 for ; Fri, 6 Nov 2015 00:26:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=SF2BZueO; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=sFW 9RUmvjUzryQQY938zxlfoQVB3Q+/i6tlg1SuUkfTRMPuflrU2Si43C3bNQysnYkW T0hbsgYrEyNzdgTquzx0vfLlFI7gUWKja1gVxAnrYYTW6ZYVj3zwB75JslssriHm maowDE9k++eH9ln7+Nit7V5NnWoW3IfbxvHqejPs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=Yg9TCBQYb kFzT6MHjwBAfSfKdbQ=; b=SF2BZueOrbzlSr/osxyPpNV+dNJ8MsF/69e3kp8S4 6tVlpu/xO96S4EJ385Ip4OTBbtPUTSOgV6gLIKCUlX0gPNEz/yMrxiZYrYLB5YTZ g1X4THh7CFbFa2y08hOdCOjA/OoyTbeVrIwiP+Z26y40HAHfa+fqzydQrYAlscHZ 70= Received: (qmail 23627 invoked by alias); 5 Nov 2015 13:26:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 23612 invoked by uid 89); 5 Nov 2015 13:26:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Nov 2015 13:26:49 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-23-423vfLz6S9OpmA4xksznkg-1; Thu, 05 Nov 2015 13:26:43 +0000 Received: from arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 5 Nov 2015 13:26:43 +0000 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, hjl.tools@gmail.com Subject: Re: [PATCH] tree-scalar-evolution.c: Handle LSHIFT by constant Date: Thu, 5 Nov 2015 13:26:15 +0000 Message-Id: <1446729975-13374-1-git-send-email-alan.lawrence@arm.com> In-Reply-To: References: X-MC-Unique: 423vfLz6S9OpmA4xksznkg-1 X-IsSubscribed: yes On 3 November 2015 at 11:35, Richard Biener wrote: > > I think this should simply re-write A << B to (type) (unsigned-type) A > * (1U << B). > > Does that then still vectorize the signed case? I didn't realize our representation of chrec's could express that. Yes, it does - thanks! (And the avx512ifma- test is compiled without warnings.) Patch attached. I've added a platform-independent version of the failing AVX512 test too. --Alan gcc/ChangeLog: PR tree-optimization/65963 * tree-scalar-evolution.c (interpret_rhs_expr): Try to handle LSHIFT_EXPRs as equivalent unsigned MULT_EXPRs. gcc/testsuite/ChangeLog: * gcc.dg/pr68112.c: New. * gcc.dg/vect/vect-strided-shift-1.c: New. --- gcc/testsuite/gcc.dg/pr68112.c | 11 ++++++++ gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 ++++++++++++++++++++++++ gcc/tree-scalar-evolution.c | 17 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr68112.c create mode 100644 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c diff --git a/gcc/testsuite/gcc.dg/pr68112.c b/gcc/testsuite/gcc.dg/pr68112.c new file mode 100644 index 0000000..0a45b03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68112.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Waggressive-loop-optimizations" } */ + +int *a; + +void +foo () +{ + for (int i = 0; i < 65536; i++) + *a = i << 24; +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c new file mode 100644 index 0000000..b1ce2ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c @@ -0,0 +1,33 @@ +/* PR tree-optimization/65963. */ +#include "tree-vect.h" + +#define N 512 + +int in[2*N], out[N]; + +__attribute__ ((noinline)) void +loop (void) +{ + for (int i = 0; i < N; i++) + out[i] = in[i << 1] + 7; +} + +int +main (int argc, char **argv) +{ + check_vect (); + for (int i = 0; i < 2*N; i++) + { + in[i] = i; + __asm__ volatile ("" : : : "memory"); + } + loop (); + __asm__ volatile ("" : : : "memory"); + for (int i = 0; i < N; i++) + { + if (out[i] != i*2 + 7) + abort (); + } + return 0; +} +/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 1 "vect" { target { vect_strided2 } } } } */ diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index 0753bf3..60d515d 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -1840,6 +1840,23 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt, res = chrec_fold_multiply (type, chrec1, chrec2); break; + case LSHIFT_EXPR: + { + /* Handle A<