From patchwork Tue Mar 1 19:59:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 590709 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9DB61140BA5 for ; Wed, 2 Mar 2016 07:00:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bzVp7UtS; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Os4HiYwnH4kyg7Xa8Y/GtFfyD30bQXiw8CKliZn76yr8TBtIUC bUqfK5/GiO9IIgezKhX1uVC3pgozCbp4w8VFIH0moXCxqn1C+xOvpifRIZBpWWCv BEHuyQbwEOyCfVmQiq0+1Ob6jV/ih4UrHVLKps/t2Oolz0UV/7UucO2GE= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=cOSwOLBJ2pQWUungo3SLlHxPIqY=; b=bzVp7UtSr6PSo0GA3OIH Csr+I2tsdFyKyADxa0nnGkB7urYEIKef5EaKlGb7Tp4M8S0vo1tbm8iYvkuH0PGk rNeNnYE9LrAOHNamZWZuotN98DqpwZ+PnQgfsKpO3d0Oj6NaNAOz4CNlW1O7h/hR TkciNc5WeEPx1m/g9fccuLk= Received: (qmail 55754 invoked by alias); 1 Mar 2016 19:59:46 -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 55727 invoked by uid 89); 1 Mar 2016 19:59:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=BAYES_20, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:define_, D*1, copying3, tem X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 01 Mar 2016 19:59:43 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 3D91D627FA; Tue, 1 Mar 2016 19:59:42 +0000 (UTC) Received: from anchor.twiddle.net (vpn-231-135.phx2.redhat.com [10.3.231.135]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u21Jxfnt027769; Tue, 1 Mar 2016 14:59:41 -0500 To: gcc-patches@gcc.gnu.org, Richard Biener From: Richard Henderson Subject: [PATCH, match] Fix pr68714 X-Enigmail-Draft-Status: N1110 Message-ID: <56D5F4AC.9030504@redhat.com> Date: Tue, 1 Mar 2016 11:59:40 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 X-IsSubscribed: yes This is similar to Mark Gilsse's patch in the OP, except that it ensures that the expression will fold back to a single condition. I did include Richi's patch from #c6 to make it more likely to trigger asap. I'd appreciate feedback on the match.pd changes; it's my first time looking into this new(ish) mini-language. r~ * gimplify.c (gimplify_expr) [VEC_COND_EXPR]: Allow the first argument to be is_gimple_condexpr. * match.pd: Simplify and + ior of vec_cond. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 7be6bd7..c434e55 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -10773,8 +10773,21 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, goto expr_2; } - case FMA_EXPR: case VEC_COND_EXPR: + { + gimplify_status r0, r1, r2; + r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, + post_p, is_gimple_condexpr, fb_rvalue); + r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, + post_p, is_gimple_val, fb_rvalue); + r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p, + post_p, is_gimple_val, fb_rvalue); + ret = MIN (MIN (r0, r1), r2); + recalculate_side_effects (*expr_p); + break; + } + + case FMA_EXPR: case VEC_PERM_EXPR: /* Classified as tcc_expression. */ goto expr_3; diff --git a/gcc/match.pd b/gcc/match.pd index 5903782..4192d29 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see real_zerop real_onep real_minus_onep zerop CONSTANT_CLASS_P + COMPARISON_CLASS_P tree_expr_nonnegative_p integer_valued_real_p integer_pow2p @@ -2452,6 +2453,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) replace if (x == 0) with tem = ~x; if (tem != 0) which is clearly less optimal and which we'll transform again in forwprop. */ +/* Simplification of vec_cond. */ + +(for bcode (bit_and bit_ior) + (simplify + (bcode (vec_cond COMPARISON_CLASS_P@0 integer_all_onesp@2 integer_zerop@3) + (vec_cond COMPARISON_CLASS_P@1 @2 @3)) + (with + { + tree al = TREE_OPERAND (@0, 0); + tree ar = TREE_OPERAND (@0, 1); + tree bl = TREE_OPERAND (@1, 0); + tree br = TREE_OPERAND (@1, 1); + } + (if (operand_equal_p (al, bl, 0) && operand_equal_p (ar, br, 0)) + (with + { + tree_code tcode + = bcode == BIT_AND_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR; + tree folded + = combine_comparisons (UNKNOWN_LOCATION, tcode, TREE_CODE (@0), + TREE_CODE (@1), TREE_TYPE (@0), al, ar); + } + (if (folded) + (switch + (if (integer_truep (folded)) @2) + (if (integer_zerop (folded)) @3) + (if (COMPARISON_CLASS_P (folded)) + { build3 (VEC_COND_EXPR, TREE_TYPE (@2), folded, @2, @3); }))) + ))))) /* Simplification of math builtins. These rules must all be optimizations as well as IL simplifications. If there is a possibility that the new