From patchwork Fri Oct 12 14:07:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 191134 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]) by ozlabs.org (Postfix) with SMTP id 2D4E72C0090 for ; Sat, 13 Oct 2012 01:07:52 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1350655674; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=W/X0VcoYbVSWW7IMoPxx+A0D+9c=; b=uXktqUDALYs5v7s srLn+shWh3zh0AmFs7okYCb8YVSF/JYtirqBzaYifjt5cCiZsRivfFBqsdzqINbW smX7gJb9wOaBOyQ8Ec4z2LUCnPthyf4uMV2cjbLAl6HdCj/Wd1kw2aDmqi/SLfVu vLpcFUNqNyMT3WR1ngrtiM5gpQhU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=tE5hmviV9cr1Tp1UU1Z4NKwMHH2w0JchEZmWdC9U7EMbkEJ7C6hAT0qXOrOAUt 7hOfFNJAd4mIBW/rW+V8kIcBIVAQgc/uIen7a6PrCbbR/qJNGWe57NIEllyd3NRW nrxwf8wlcrKJsiLzJnD5oqWw0fqpiPEKptMBX0A/2gU98=; Received: (qmail 6896 invoked by alias); 12 Oct 2012 14:07:48 -0000 Received: (qmail 6886 invoked by uid 22791); 12 Oct 2012 14:07:47 -0000 X-SWARE-Spam-Status: No, hits=-8.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail4-relais-sop.national.inria.fr (HELO mail4-relais-sop.national.inria.fr) (192.134.164.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 12 Oct 2012 14:07:43 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 12 Oct 2012 16:07:41 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TMftt-0007j8-6u; Fri, 12 Oct 2012 16:07:41 +0200 Date: Fri, 12 Oct 2012 16:07:41 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org cc: Richard Biener Subject: Re: Constant-fold vector comparisons In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 On Sat, 29 Sep 2012, Marc Glisse wrote: > 1) it handles constant folding of vector comparisons, > > 2) it fixes another place where vectors are not expected Here is a new version of this patch. In a first try, I got bitten by the operator priorities in "a && b?c:d", which g++ doesn't warn about. 2012-10-12 Marc Glisse gcc/ * tree-ssa-forwprop.c (forward_propagate_into_cond): Handle vectors. * fold-const.c (fold_relational_const): Handle VECTOR_CST. gcc/testsuite/ * gcc.dg/tree-ssa/foldconst-6.c: New testcase. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 192400) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -570,40 +570,43 @@ forward_propagate_into_cond (gimple_stmt code = gimple_assign_rhs_code (def_stmt); if (TREE_CODE_CLASS (code) == tcc_comparison) tmp = fold_build2_loc (gimple_location (def_stmt), code, TREE_TYPE (cond), gimple_assign_rhs1 (def_stmt), gimple_assign_rhs2 (def_stmt)); else if ((code == BIT_NOT_EXPR && TYPE_PRECISION (TREE_TYPE (cond)) == 1) || (code == BIT_XOR_EXPR - && integer_onep (gimple_assign_rhs2 (def_stmt)))) + && ((gimple_assign_rhs_code (stmt) == VEC_COND_EXPR) + ? integer_all_onesp (gimple_assign_rhs2 (def_stmt)) + : integer_onep (gimple_assign_rhs2 (def_stmt))))) { tmp = gimple_assign_rhs1 (def_stmt); swap = true; } } if (tmp && is_gimple_condexpr (tmp)) { if (dump_file && tmp) { fprintf (dump_file, " Replaced '"); print_generic_expr (dump_file, cond, 0); fprintf (dump_file, "' with '"); print_generic_expr (dump_file, tmp, 0); fprintf (dump_file, "'\n"); } - if (integer_onep (tmp)) + if ((gimple_assign_rhs_code (stmt) == VEC_COND_EXPR) + ? integer_all_onesp (tmp) : integer_onep (tmp)) gimple_assign_set_rhs_from_tree (gsi_p, gimple_assign_rhs2 (stmt)); else if (integer_zerop (tmp)) gimple_assign_set_rhs_from_tree (gsi_p, gimple_assign_rhs3 (stmt)); else { gimple_assign_set_rhs1 (stmt, unshare_expr (tmp)); if (swap) { tree t = gimple_assign_rhs2 (stmt); gimple_assign_set_rhs2 (stmt, gimple_assign_rhs3 (stmt)); Index: gcc/testsuite/gcc.dg/tree-ssa/foldconst-6.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/foldconst-6.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/foldconst-6.c (revision 0) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-ccp1" } */ + +typedef long vec __attribute__ ((vector_size (2 * sizeof(long)))); + +vec f () +{ + vec a = { -2, 666 }; + vec b = { 3, 2 }; + return a < b; +} + +/* { dg-final { scan-tree-dump-not "666" "ccp1"} } */ +/* { dg-final { cleanup-tree-dump "ccp1" } } */ Property changes on: gcc/testsuite/gcc.dg/tree-ssa/foldconst-6.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 192400) +++ gcc/fold-const.c (working copy) @@ -16121,20 +16121,44 @@ fold_relational_const (enum tree_code co TREE_IMAGPART (op0), TREE_IMAGPART (op1)); if (code == EQ_EXPR) return fold_build2 (TRUTH_ANDIF_EXPR, type, rcond, icond); else if (code == NE_EXPR) return fold_build2 (TRUTH_ORIF_EXPR, type, rcond, icond); else return NULL_TREE; } + if (TREE_CODE (op0) == VECTOR_CST && TREE_CODE (op1) == VECTOR_CST) + { + int count = VECTOR_CST_NELTS (op0); + tree *elts = XALLOCAVEC (tree, count); + gcc_assert (TREE_CODE (type) == VECTOR_TYPE); + + for (int i = 0; i < count; i++) + { + tree elem_type = TREE_TYPE (type); + tree elem0 = VECTOR_CST_ELT (op0, i); + tree elem1 = VECTOR_CST_ELT (op1, i); + + tree tem = fold_relational_const (code, elem_type, + elem0, elem1); + + if (tem == NULL_TREE) + return NULL_TREE; + + elts[i] = build_int_cst (elem_type, integer_zerop (tem) ? 0 : -1); + } + + return build_vector (type, elts); + } + /* From here on we only handle LT, LE, GT, GE, EQ and NE. To compute GT, swap the arguments and do LT. To compute GE, do LT and invert the result. To compute LE, swap the arguments, do LT and invert the result. To compute NE, do EQ and invert the result. Therefore, the code below must handle only EQ and LT. */ if (code == LE_EXPR || code == GT_EXPR)