From patchwork Tue Nov 3 10:15:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 539289 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 1F2AE14030E for ; Tue, 3 Nov 2015 21:16:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=u07OtybK; 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=oRo 2taRSQh0h5cmUhWFTAZbwyFx1LmdMgQ8+yVoZ/rwDZaZdkQoeNspj3IYAV7aqXTd yExygGCnrA3nwDJra31Eeev/3VacPtkXRvz4+FfQT9CKNlMkvCCnRmnzRdvuDM/A 1V6mg9D7DXWb3GpSSsv/pu+jw8VFPGz50BPM6VoI= 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=cTrZ4QfM5 BYni9jDOr6W1nJfX3o=; b=u07OtybKTa0rHs6jJZVzaQM1RmJ0bzhYNwLWrvTAo QPE4l01pk3naTOxFxou4IaAT0uQ8sqbVM/Zm9a3D2NFAyBWDuCIXkH4SaM/gMgxj Y0fhnbZ09zDXTvaEaWQ6JwfKRicYTy8TEHBQ06n4MkMiAOG09xt3EmzBQLZkuz4Z yU= Received: (qmail 5299 invoked by alias); 3 Nov 2015 10:15:58 -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 5268 invoked by uid 89); 3 Nov 2015 10:15:55 -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; Tue, 03 Nov 2015 10:15:53 +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-4-sQAYjnSGRWqY-khh7GQrVg-1; Tue, 03 Nov 2015 10:15:47 +0000 Received: from arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 3 Nov 2015 10:15:47 +0000 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Cc: hjl.tools@gmail.com, richard.guenther@gmail.com Subject: Re: [PATCH] tree-scalar-evolution.c: Handle LSHIFT by constant Date: Tue, 3 Nov 2015 10:15:27 +0000 Message-Id: <1446545727-27064-1-git-send-email-alan.lawrence@arm.com> In-Reply-To: References: X-MC-Unique: sQAYjnSGRWqY-khh7GQrVg-1 X-IsSubscribed: yes On 27/10/15 22:27, H.J. Lu wrote: > > It caused: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68112 Bah :(. So yes, in general case, we can't rewrite (a << 1) to (a * 2) as for signed types (0x7f...f) << 1 == -2 whereas (0x7f...f * 2) is undefined behaviour. Oh well :(... I don't have a really good fix for this. The best way I can see would be to try to make definedness of overflow a property of either the type, or maybe of the chrec, and settable on a finer granularity than at present, rather than TYPE_OVERFLOW_UNDEFINED = (type is signed) && !(a bunch of global flags). However, I don't think I'm going to have time for that patch before end of stage 1. So, I've reverted my r229437. There is a simpler fix: to only apply the rewrite for unsigned types. I attach that patch, which I've bootstrapped on x86; but although I think this way is correct, I'm not really sure whether this is something that should go in. Thoughts? --Alan --- gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 ++++++++++++++++++++++++ gcc/tree-scalar-evolution.c | 19 ++++++++++++++ 2 files changed, 52 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..40e6561 --- /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 (unsigned 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..d8f3d46 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -1840,6 +1840,25 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt, res = chrec_fold_multiply (type, chrec1, chrec2); break; + case LSHIFT_EXPR: + if (!TYPE_OVERFLOW_UNDEFINED (type)) + { + /* Handle A<