From patchwork Tue Oct 30 12:14:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 195470 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 A13F42C00D0 for ; Tue, 30 Oct 2012 23:15:06 +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=1352204107; 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=eMVjvycWAQWrqnzdO/1XCgkryUQ=; b=oevgscy7tJl7aab tRxMG6j2iKU50ScEKfwx5xO15JwN48g6W6+VcoGEGmJQTtxxXJ2Pj7lpVPmb46kk P8woyyW0ktUT0ysP3Vz9nIxiyQBTBqM9py0BdYE5kKXrUnMRLC/u3n8okz237NXz CIAhtr6V0aKWspBHjpyHNc0rIClI= 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=xHH3qZMftyDwiAdzvk5vQdXhqkq1wI4vhqHM/hmDwCXdL4/JienYIN4fq/DQqX YRVVyZgWBaynAilTLJoHfSTDlPtvR7bamsaVjgpSHEqtlTkApqOazMqeLtZ/ghx9 1qds6Wr5jjA9es0MGMw4h2AlHpL6xCdjuUPr/zL0C9/OM=; Received: (qmail 25618 invoked by alias); 30 Oct 2012 12:14:52 -0000 Received: (qmail 25602 invoked by uid 22791); 30 Oct 2012 12:14:48 -0000 X-SWARE-Spam-Status: No, hits=-8.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Oct 2012 12:14:42 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 30 Oct 2012 13:14:40 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TTAiO-00035f-K7; Tue, 30 Oct 2012 13:14:40 +0100 Date: Tue, 30 Oct 2012 13:14:40 +0100 (CET) From: Marc Glisse To: Marek Polacek cc: gcc-patches@gcc.gnu.org Subject: Re: Adapt one fold-const optimization for vectors In-Reply-To: <20121030092140.GB13313@redhat.com> Message-ID: References: <20121030092140.GB13313@redhat.com> 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 Tue, 30 Oct 2012, Marek Polacek wrote: > On Tue, Oct 30, 2012 at 08:05:13AM +0100, Marc Glisse wrote: >> Hello, >> >> one more optimization that needed help for vectors, it crashed on >> (x> do a x86-only one if needed). >> >> bootstrap+testsuite. >> >> 2012-10-30 Marc Glisse >> >> * fold-const.c (fold_binary_op_with_conditional_arg): Handle vectors. >> (fold_binary_loc): call it for VEC_COND_EXPR. > > Patch missing? Indeed, thanks for the notice. Here it is. Index: fold-const.c =================================================================== --- fold-const.c (revision 192976) +++ fold-const.c (working copy) @@ -5952,42 +5952,47 @@ static tree fold_binary_op_with_conditional_arg (location_t loc, enum tree_code code, tree type, tree op0, tree op1, tree cond, tree arg, int cond_first_p) { tree cond_type = cond_first_p ? TREE_TYPE (op0) : TREE_TYPE (op1); tree arg_type = cond_first_p ? TREE_TYPE (op1) : TREE_TYPE (op0); tree test, true_value, false_value; tree lhs = NULL_TREE; tree rhs = NULL_TREE; + enum tree_code cond_code = COND_EXPR; - if (TREE_CODE (cond) == COND_EXPR) + if (TREE_CODE (cond) == COND_EXPR + || TREE_CODE (cond) == VEC_COND_EXPR) { test = TREE_OPERAND (cond, 0); true_value = TREE_OPERAND (cond, 1); false_value = TREE_OPERAND (cond, 2); /* If this operand throws an expression, then it does not make sense to try to perform a logical or arithmetic operation involving it. */ if (VOID_TYPE_P (TREE_TYPE (true_value))) lhs = true_value; if (VOID_TYPE_P (TREE_TYPE (false_value))) rhs = false_value; } else { tree testtype = TREE_TYPE (cond); test = cond; true_value = constant_boolean_node (true, testtype); false_value = constant_boolean_node (false, testtype); } + if (TREE_CODE (TREE_TYPE (test)) == VECTOR_TYPE) + cond_code = VEC_COND_EXPR; + /* This transformation is only worthwhile if we don't have to wrap ARG in a SAVE_EXPR and the operation can be simplified on at least one of the branches once its pushed inside the COND_EXPR. */ if (!TREE_CONSTANT (arg) && (TREE_SIDE_EFFECTS (arg) || TREE_CONSTANT (true_value) || TREE_CONSTANT (false_value))) return NULL_TREE; arg = fold_convert_loc (loc, arg_type, arg); if (lhs == 0) @@ -6004,21 +6009,21 @@ fold_binary_op_with_conditional_arg (loc if (cond_first_p) rhs = fold_build2_loc (loc, code, type, false_value, arg); else rhs = fold_build2_loc (loc, code, type, arg, false_value); } /* Check that we have simplified at least one of the branches. */ if (!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && !TREE_CONSTANT (rhs)) return NULL_TREE; - return fold_build3_loc (loc, COND_EXPR, type, test, lhs, rhs); + return fold_build3_loc (loc, cond_code, type, test, lhs, rhs); } /* Subroutine of fold() that checks for the addition of +/- 0.0. If !NEGATE, return true if ADDEND is +/-0.0 and, for all X of type TYPE, X + ADDEND is the same as X. If NEGATE, return true if X - ADDEND is the same as X. X + 0 and X - 0 both give X when X is NaN, infinite, or nonzero @@ -9864,30 +9869,34 @@ fold_binary_loc (location_t loc, if (TREE_CODE (arg1) == COMPOUND_EXPR && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) { tem = fold_build2_loc (loc, code, type, op0, fold_convert_loc (loc, TREE_TYPE (op1), TREE_OPERAND (arg1, 1))); return build2_loc (loc, COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), tem); } - if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) + if (TREE_CODE (arg0) == COND_EXPR + || TREE_CODE (arg0) == VEC_COND_EXPR + || COMPARISON_CLASS_P (arg0)) { tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1, arg0, arg1, /*cond_first_p=*/1); if (tem != NULL_TREE) return tem; } - if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) + if (TREE_CODE (arg1) == COND_EXPR + || TREE_CODE (arg1) == VEC_COND_EXPR + || COMPARISON_CLASS_P (arg1)) { tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1, arg1, arg0, /*cond_first_p=*/0); if (tem != NULL_TREE) return tem; } } switch (code)