From patchwork Thu Apr 11 17:38:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 235843 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 477852C00B9 for ; Fri, 12 Apr 2013 03:39:01 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=mPOS7iU3qIzBUAgk 2VfddA4Jux7aKi90OPwtdf5xjBFg8j/kRQuK5WT71NO6u/hcl26gASexz7ULdUPy 7euqN/Vx4b58zW/JJEWDiH/WZLGPg7/pnzsm9h2mPMJzSCB3a4POfL6oyx8/KU/0 DzGopxHkRcfuiX3TIXzrFdNJfbY= 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=ruoHVjz64mCRagARPfAtHf poLX4=; b=Jp5l8OVztQjFEkEtse6GcX0AS0R+Nc/FUlccmKoXSEIaZpYIbejh0m mBHnsLOR6kQpTh/8YGi7bF8D6MO4BcelMifgPLw9w14Vt8FArH+VmjEFTYLKmamT pqTOqO9U6ToqOtzbVt/Jknteh2bH+UcbaHz/o+uVa9VHTvpwyvC/I= Received: (qmail 1130 invoked by alias); 11 Apr 2013 17:38:55 -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 1077 invoked by uid 89); 11 Apr 2013 17:38:55 -0000 X-Spam-SWARE-Status: No, score=-8.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 11 Apr 2013 17:38:54 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 11 Apr 2013 19:38:33 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1UQLSD-0000ya-1I; Thu, 11 Apr 2013 19:38:33 +0200 Date: Thu, 11 Apr 2013 19:38:33 +0200 (CEST) From: Marc Glisse To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: Fold {2, 3, 4, 5} >> 31 In-Reply-To: <20130411162953.GQ16463@tucnak.redhat.com> Message-ID: References: <20130411162953.GQ16463@tucnak.redhat.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Found: No On Thu, 11 Apr 2013, Jakub Jelinek wrote: > On Thu, Apr 11, 2013 at 06:24:02PM +0200, Marc Glisse wrote: >> here is a patch to handle constant folding of mixed vector-integer >> operations. I could have shared the loop with the vector-vector >> case, but that would have meant re-testing if arg2 was a vector at >> every iteration (I can go back to that version if you prefer). > > Yeah, that is the kind of thinking I had too. > >> + /* Shifts allow a scalar offset for a vector. */ >> + if (TREE_CODE (arg1) == VECTOR_CST) > > I'd prefer && TREE_CODE (arg2) == INTEGER_CST added to the condition > here. :-) I added and removed it a few times before deciding. > Please use just one space. > And please use tabs where possible, instead of 8 spaces. Argh, I fixed a couple formatting issues before copy-pasting, but I had missed quite a few. > Have you tested the testcase say for -m32 -mno-sse too, to see > if it doesn't fail without HW vector support? Yes. > If so, the patch is ok with the above mentioned changes. Ok, I'll retest during the night. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 197819) +++ gcc/fold-const.c (working copy) @@ -1335,35 +1335,58 @@ const_binop (enum tree_code code, tree a return NULL_TREE; } if (real && imag) return build_complex (type, real, imag); } if (TREE_CODE (arg1) == VECTOR_CST && TREE_CODE (arg2) == VECTOR_CST) { - tree type = TREE_TYPE(arg1); + tree type = TREE_TYPE (arg1); int count = TYPE_VECTOR_SUBPARTS (type), i; - tree *elts = XALLOCAVEC (tree, count); + tree *elts = XALLOCAVEC (tree, count); for (i = 0; i < count; i++) { - tree elem1 = VECTOR_CST_ELT (arg1, i); + tree elem1 = VECTOR_CST_ELT (arg1, i); tree elem2 = VECTOR_CST_ELT (arg2, i); - elts[i] = const_binop (code, elem1, elem2); + elts[i] = const_binop (code, elem1, elem2); - /* It is possible that const_binop cannot handle the given - code and return NULL_TREE */ - if(elts[i] == NULL_TREE) - return NULL_TREE; + /* It is possible that const_binop cannot handle the given + code and return NULL_TREE */ + if (elts[i] == NULL_TREE) + return NULL_TREE; + } + + return build_vector (type, elts); + } + + /* Shifts allow a scalar offset for a vector. */ + if (TREE_CODE (arg1) == VECTOR_CST + && TREE_CODE (arg2) == INTEGER_CST) + { + tree type = TREE_TYPE (arg1); + int count = TYPE_VECTOR_SUBPARTS (type), i; + tree *elts = XALLOCAVEC (tree, count); + + for (i = 0; i < count; i++) + { + tree elem1 = VECTOR_CST_ELT (arg1, i); + + elts[i] = const_binop (code, elem1, arg2); + + /* It is possible that const_binop cannot handle the given + code and return NULL_TREE */ + if (elts[i] == NULL_TREE) + return NULL_TREE; } return build_vector (type, elts); } return NULL_TREE; } /* Create a sizetype INT_CST node with NUMBER sign extended. KIND indicates which particular sizetype to create. */ @@ -9852,21 +9875,22 @@ fold_binary_loc (location_t loc, STRIP_NOPS (arg1); } /* Note that TREE_CONSTANT isn't enough: static var addresses are constant but we can't do arithmetic on them. */ if ((TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) || (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST) || (TREE_CODE (arg0) == FIXED_CST && TREE_CODE (arg1) == FIXED_CST) || (TREE_CODE (arg0) == FIXED_CST && TREE_CODE (arg1) == INTEGER_CST) || (TREE_CODE (arg0) == COMPLEX_CST && TREE_CODE (arg1) == COMPLEX_CST) - || (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)) + || (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST) + || (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == INTEGER_CST)) { if (kind == tcc_binary) { /* Make sure type and arg0 have the same saturating flag. */ gcc_assert (TYPE_SATURATING (type) == TYPE_SATURATING (TREE_TYPE (arg0))); tem = const_binop (code, arg0, arg1); } else if (kind == tcc_comparison) tem = fold_relational_const (code, type, arg0, arg1); Index: gcc/testsuite/gcc.dg/fold-cstvecshift.c =================================================================== --- gcc/testsuite/gcc.dg/fold-cstvecshift.c (revision 0) +++ gcc/testsuite/gcc.dg/fold-cstvecshift.c (revision 0) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-ccp1" } */ + +typedef int vec __attribute__ ((vector_size (4 * sizeof (int)))); + +void f (vec *r) +{ + vec a = { 2, 3, 4, 5 }; + *r = (a << 2) >> 1; +} + +/* { dg-final { scan-tree-dump "{ 4, 6, 8, 10 }" "ccp1"} } */ +/* { dg-final { cleanup-tree-dump "ccp1" } } */