From patchwork Sun Mar 31 13:31:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 232610 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 16B572C0084 for ; Mon, 1 Apr 2013 00:31:51 +1100 (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:subject:message-id:mime-version:content-type; q=dns; s= default; b=Ka3suNLFFYmygTsxmrLEXz47MEo2XHtI2hElkyDnBLzM3ypyPLwaS jd/jKqDqPlgcszCN6exbzpGQNqdywJmOCSlpPzQC1v7S4XR1/Fm3OkmUbdFiLMUP lpM83BquMeWi8l4OAS1W7d/0a9hALQJX5HTaRT2596Cxc5FH+5bV30= 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:subject:message-id:mime-version:content-type; s= default; bh=mdy7N1xEsfZrsfnus0sMuvlwDOA=; b=KDtg9ytlMYzDTcZdVp2l FdYWev0mfepXIHuftnKMuqdju5Dk4N6BXeGDFoBi3N4p5FqM3QpY55/hctjyhDuc yousAkrSpJSggTilwdfxYRxErrw1hmeBk8Ptb751qciZYKAMYAinTHp+6SDMPRFT vHHX4PT+BKSbxwcirrGB+ac= Received: (qmail 30930 invoked by alias); 31 Mar 2013 13:31: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 30866 invoked by uid 89); 31 Mar 2013 13:31:30 -0000 X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 31 Mar 2013 13:31:26 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 31 Mar 2013 15:31:24 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1UMIM0-0006gP-0I for gcc-patches@gcc.gnu.org; Sun, 31 Mar 2013 15:31:24 +0200 Date: Sun, 31 Mar 2013 15:31:23 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Constant folding of VEC_COND_EXPR Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Found: No Hello, this adds constant folding of VEC_COND_EXPR at the tree level by forwarding to the VEC_PERM_EXPR code (a merge is a special case of a permutation). The CONSTRUCTOR case may be unreachable for now (it will probably need an extra piece of code in tree-ssa-forwprop.c), but it seems better to add it at the same time. bootstrap+testsuite on x86_64-linux-gnu. 2013-03-31 Marc Glisse PR tree-optimization/56790 * fold-const.c (fold_ternary_loc) : Add constant folding. testsuite/ * g++.dg/ext/pr56790-1.C: New testcase. Index: gcc/testsuite/g++.dg/ext/pr56790-1.C =================================================================== --- gcc/testsuite/g++.dg/ext/pr56790-1.C (revision 0) +++ gcc/testsuite/g++.dg/ext/pr56790-1.C (revision 0) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ccp1" } */ + +typedef long vec __attribute__ ((vector_size (2 * sizeof (long)))); + +vec f (void) +{ + vec a = { 5, 7 }; + vec b = { 11, 13 }; + vec m = { -1, 0 }; + return m ? a : b; +} + +/* { dg-final { scan-tree-dump "{ 5, 13 }" "ccp1" } } */ +/* { dg-final { scan-tree-dump-not "VEC_COND_EXPR" "ccp1" } } */ +/* { dg-final { cleanup-tree-dump "ccp1" } } */ Property changes on: gcc/testsuite/g++.dg/ext/pr56790-1.C ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 197284) +++ gcc/fold-const.c (working copy) @@ -13917,20 +13917,43 @@ fold_ternary_loc (location_t loc, enum t || VOID_TYPE_P (type))) return pedantic_non_lvalue_loc (loc, tem); return NULL_TREE; } else if (TREE_CODE (arg0) == VECTOR_CST) { if (integer_all_onesp (arg0)) return pedantic_omit_one_operand_loc (loc, type, arg1, arg2); if (integer_zerop (arg0)) return pedantic_omit_one_operand_loc (loc, type, arg2, arg1); + + if ((TREE_CODE (arg1) == VECTOR_CST + || TREE_CODE (arg1) == CONSTRUCTOR) + && (TREE_CODE (arg2) == VECTOR_CST + || TREE_CODE (arg2) == CONSTRUCTOR)) + { + unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i; + unsigned char *sel = XALLOCAVEC (unsigned char, nelts); + gcc_assert (nelts == VECTOR_CST_NELTS (arg0)); + for (i = 0; i < nelts; i++) + { + tree val = VECTOR_CST_ELT (arg0, i); + if (integer_all_onesp (val)) + sel[i] = i; + else if (integer_zerop (val)) + sel[i] = nelts + i; + else + gcc_unreachable (); + } + tree t = fold_vec_perm (type, arg1, arg2, sel); + if (t != NULL_TREE) + return t; + } } if (operand_equal_p (arg1, op2, 0)) return pedantic_omit_one_operand_loc (loc, type, arg1, arg0); /* If we have A op B ? A : C, we may be able to convert this to a simpler expression, depending on the operation and the values of B and C. Signed zeros prevent all of these transformations, for reasons given above each one.