From patchwork Fri Oct 16 15:25:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 531397 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 C046C1402B0 for ; Sat, 17 Oct 2015 02:25:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=S5FzFTGN; 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:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=Rg3/nhpuAn3qY6DZ dMSLQbYBMPfYOfxtyZXMTzjggJthLU+hCq/J7SFA4XiS4g90Z3TYzti0JNa3m3MZ czq1QPcHoCKBDZF+D5TEaoA0A5/18xoFtmPlCGpLyeGPulzfmO6/Agla2o0lN01b bFTnFbtJUYTq3hbQPcv/+eDdcBs= 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:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=mUCoQDVdS1+kQBx+SeaijE AdF1I=; b=S5FzFTGN6mxOa1R0j2fTmOYkln75iqJ+QNF4RXeTZRNy12BWfXuQov 14FalJNWknB1e0RsS+k991xhOzZnBs3QmgNyVe+e+EmKVhueksmihIWz3c1woiNd nWKxQrBbhvMf5Lzs5FsazcYmR0GCQkziPqaWFprH6VFb8ujKomeBg= Received: (qmail 7894 invoked by alias); 16 Oct 2015 15:25:28 -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 7883 invoked by uid 89); 16 Oct 2015 15:25:27 -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) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Oct 2015 15:25:24 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-16-omHtDp_FQSOPLEDwc9S05g-1; Fri, 16 Oct 2015 16:25:19 +0100 Received: from arm.com ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 16 Oct 2015 16:25:19 +0100 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-scalar-evolution.c: Handle LSHIFT by constant Date: Fri, 16 Oct 2015 16:25:06 +0100 Message-Id: <1445009106-15011-1-git-send-email-alan.lawrence@arm.com> X-MC-Unique: omHtDp_FQSOPLEDwc9S05g-1 X-IsSubscribed: yes This lets the vectorizer handle some simple strides expressed using left-shift rather than mul, e.g. a[i << 1] (whereas previously only a[i * 2] would have been handled). This patch does *not* handle the general case of shifts - neither a[i << j] nor a[1 << i] will be handled; that would be a significantly bigger patch (probably duplicating or generalizing much of chrec_fold_multiply and chrec_fold_multiply_poly_poly in tree-chrec.c), and would probably also only be applicable to machines with gather-load support. Bootstrapped+check-gcc,g++,gfortran on x86_64, AArch64 and ARM, also Ada on x86_64. Is this OK for trunk? gcc/ChangeLog: PR tree-optimization/65963 * tree-scalar-evolution.c (interpret_rhs_expr): Handle some LSHIFT_EXPRs as equivalent MULT_EXPRs. gcc/testsuite/ChangeLog: * gcc.dg/vect/vect-strided-shift-1.c: New. --- gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 ++++++++++++++++++++++++ gcc/tree-scalar-evolution.c | 18 +++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c 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..e478b0e 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -1831,12 +1831,30 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt, break; case MULT_EXPR: + case LSHIFT_EXPR: + /* Handle A< TYPE_PRECISION (type)) + type = TREE_TYPE (chrec1); + if (TYPE_PRECISION (type) == 0) + { + res = chrec_dont_know; + break; + } + chrec2 = fold_build2 (LSHIFT_EXPR, type, + build_int_cst (type, 1), + chrec2); + } res = chrec_fold_multiply (type, chrec1, chrec2); break;