From patchwork Thu Apr 25 21:47:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 239599 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 42D0A2C00EF for ; Fri, 26 Apr 2013 07:47:18 +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:mime-version :content-type; q=dns; s=default; b=wTf7ovWwgo0gBoGl1nLPqyepyPDKY u1hdZ3TEMnF/9UXWKYyEuRv02lbRp0rrJKA9tJkJTHj6DNQWEsNX+6KyPVUhbzyE 1Ak/p3pzbqnsnxJKe0dTUNg6WHLSBKLx7KWm/x+fr8QSjIx8Dhn7I/mIrpATtWay qHqbpIZZgK/uRw= 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:mime-version :content-type; s=default; bh=UCK9QM6J5FnQTqq0SKjLYjVhyxs=; b=lUE x+S7Gs026fcpbjW3d4DjNZo1T3fCe1MgAFywPQxF5raSwTZMd8x6yG9n2RF0ivhm 2o3CjZB02nuapDR7l2sSFsx++Grwlb5jTYYfbEc4Q+X894foXHjU9I7HtSGoos9a 0KmNwIn3XefrTEbE/XZRi5XYuREPEYkLutAm4r3E= Received: (qmail 24801 invoked by alias); 25 Apr 2013 21:47:11 -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 24791 invoked by uid 89); 25 Apr 2013 21:47:10 -0000 X-Spam-SWARE-Status: No, score=-6.4 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; Thu, 25 Apr 2013 21:47:10 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3PLl9dS015924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Apr 2013 17:47:09 -0400 Received: from zalov.cz (vpn-61-36.rdu2.redhat.com [10.10.61.36]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3PLl7Db001333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Apr 2013 17:47:08 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r3PLl5nA010533; Thu, 25 Apr 2013 23:47:06 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r3PLl4TD010532; Thu, 25 Apr 2013 23:47:04 +0200 Date: Thu, 25 Apr 2013 23:47:02 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fold VEC_[LR]SHIFT_EXPR (PR tree-optimization/57051) Message-ID: <20130425214702.GJ28963@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-04-25 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. Jakub --- gcc/fold-const.c.jj 2013-04-12 10:16:25.000000000 +0200 +++ gcc/fold-const.c 2013-04-24 12:37:11.789122719 +0200 @@ -1380,17 +1380,42 @@ const_binop (enum tree_code code, tree a int count = TYPE_VECTOR_SUBPARTS (type), i; tree *elts = XALLOCAVEC (tree, count); - for (i = 0; i < count; i++) + if (code == VEC_LSHIFT_EXPR + || code == VEC_RSHIFT_EXPR) { - tree elem1 = VECTOR_CST_ELT (arg1, i); - - elts[i] = const_binop (code, elem1, arg2); + if (!host_integerp (arg2, 1)) + return NULL_TREE; - /* It is possible that const_binop cannot handle the given - code and return NULL_TREE */ - if (elts[i] == 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 + 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); }