From patchwork Fri May 3 13:18:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 241310 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 977502C0095 for ; Fri, 3 May 2013 23:18:43 +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:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=TIBC6Tp1HN5F21O2I izcs1pkRajhksYLvi23LQi2BggbG4MM4K9Mw5Obfvdayhn5blm+/1gw57ijKQi26 mC30R1TxU1++wfMW+6wqc5GVDWGLb2gcLFL2yqKL37nSJ5Phqu76lILx0Xop1bDx 6P7k6BYYyXzMOUlXvUr+AHQZ+g= 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:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=cUpqHSEB/5o2XJUKL1li9AP GuUA=; b=oq3AfFV0ueKv/7nMAYmy9QxJsUCMmp5iQa2ef9KTuPaohk0JR5DcVYi jH0LunSQFLCo30LkGiDwICT1J7W6gZ1eePBImZIugh5hm27g6qQ2/OjZbnRvPYAV 9i6SxWMgpaIlGStWwekbdrB0Y+ZhSm70m8Mp6/iUzreE2rd1lgmQ= Received: (qmail 31464 invoked by alias); 3 May 2013 13:18:37 -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 31454 invoked by uid 89); 3 May 2013 13:18:36 -0000 X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 03 May 2013 13:18:36 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r43DIYG4030031 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 May 2013 09:18:35 -0400 Received: from zalov.cz (vpn-57-105.rdu2.redhat.com [10.10.57.105]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r43DIX1c009383 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 3 May 2013 09:18:34 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r43DIVsx002175; Fri, 3 May 2013 15:18:32 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r43DIUkZ002174; Fri, 3 May 2013 15:18:30 +0200 Date: Fri, 3 May 2013 15:18:29 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fold VEC_[LR]SHIFT_EXPR (PR tree-optimization/57051) Message-ID: <20130503131829.GC28963@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20130425214702.GJ28963@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130425214702.GJ28963@tucnak.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) On Thu, Apr 25, 2013 at 11:47:02PM +0200, Jakub Jelinek wrote: > This patch adds folding of constant arguments v>> and v<<, which helps to > optimize the testcase from the PR back into constant store after vectorized > loop is unrolled. As this fixes a regression on the 4.8 branch, I've backported it (and minimal prerequisite for that) to 4.8 branch too. As the non-whole vector shifts VECTOR_CST by INTEGER_CST don't have any testcase showing a regression, I've left those out (trunk has instead of that else return NULL_TREE; code to handle those). 2013-05-03 Jakub Jelinek Backported from mainline 2013-04-26 Jakub Jelinek PR tree-optimization/57051 * fold-const.c (const_binop): Handle VEC_LSHIFT_EXPR and VEC_RSHIFT_EXPR if shift count is a multiple of element bitsize. 2013-04-12 Marc Glisse * fold-const.c (fold_binary_loc): Call const_binop also for mixed vector-scalar operations. Jakub --- gcc/fold-const.c (revision 198579) +++ gcc/fold-const.c (working copy) @@ -1366,6 +1366,44 @@ const_binop (enum tree_code code, tree a 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); + + if (code == VEC_LSHIFT_EXPR + || code == VEC_RSHIFT_EXPR) + { + if (!host_integerp (arg2, 1)) + return NULL_TREE; + + unsigned HOST_WIDE_INT shiftc = tree_low_cst (arg2, 1); + unsigned HOST_WIDE_INT outerc = tree_low_cst (TYPE_SIZE (type), 1); + unsigned HOST_WIDE_INT innerc + = tree_low_cst (TYPE_SIZE (TREE_TYPE (type)), 1); + if (shiftc >= outerc || (shiftc % innerc) != 0) + return NULL_TREE; + int offset = shiftc / innerc; + if (code == VEC_LSHIFT_EXPR) + offset = -offset; + tree zero = build_zero_cst (TREE_TYPE (type)); + for (i = 0; i < count; i++) + { + if (i + offset < 0 || i + offset >= count) + elts[i] = zero; + else + elts[i] = VECTOR_CST_ELT (arg1, i + offset); + } + } + else + return NULL_TREE; + + return build_vector (type, elts); + } return NULL_TREE; } @@ -9862,7 +9900,8 @@ fold_binary_loc (location_t loc, || (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) {