From patchwork Wed Jul 1 13:03:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 490134 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 6DCC71402AD for ; Wed, 1 Jul 2015 23:03:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=hRQwTZqW; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=kkHrA9LCU4/VeH6jOSixR33fONvINhtAkTPgZllCjjCGRRsPt8eZx ZJZVjgTgepi6IjZ2AX95KcCwAiWNAaducB+eAY/P0FmOKcwAWg9/chMhTYy0AshN 9PUS9jFN7/zQgu/OHOiqH5ERCINlZhOJQWM+KaL6rapMFwzMQbruqo= 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=xQZeY48piqS9GOpLeDS7I7bJfwQ=; b=hRQwTZqWBauRHS7Qplek tkUCZHBXYlkUG/bJC+qQqnoDnZvCAedJgzpzGURJdCTcvuPvA5Ba/fce8Ef5vYp4 nGy/teoEe9LYVsTMEt43OViWmzajVh+rDlPbOGNtndVJTiL2IQZmX2WVEdAChsH1 G2k7ylTspu9pi/tc8iD0AP0= Received: (qmail 41362 invoked by alias); 1 Jul 2015 13:03:35 -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 41353 invoked by uid 89); 1 Jul 2015 13:03:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 01 Jul 2015 13:03:33 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 71950ADB7 for ; Wed, 1 Jul 2015 13:03:30 +0000 (UTC) Date: Wed, 1 Jul 2015 15:03:30 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][10/n] Remove GENERIC stmt combining from SCCVN Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 This merges the complete comparison patterns from the match-and-simplify branch, leaving incomplete implementations of fold-const.c code alone. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2015-07-01 Richard Biener * fold-const.c (fold_comparison): Move X - Y CMP 0 -> X CMP Y, X * C1 CMP 0 -> X CMP 0, X CMP X, ~X CMP ~Y -> Y CMP X and ~X CMP C -> X CMP' ~C to ... * match.pd: ... patterns here. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 225225) +++ gcc/fold-const.c (working copy) @@ -8783,23 +8734,6 @@ fold_comparison (location_t loc, enum tr } } - /* Transform comparisons of the form X - Y CMP 0 to X CMP Y. */ - if (TREE_CODE (arg0) == MINUS_EXPR - && equality_code - && integer_zerop (arg1)) - { - /* ??? The transformation is valid for the other operators if overflow - is undefined for the type, but performing it here badly interacts - with the transformation in fold_cond_expr_with_comparison which - attempts to synthetize ABS_EXPR. */ - if (!equality_code) - fold_overflow_warning ("assuming signed overflow does not occur " - "when changing X - Y cmp 0 to X cmp Y", - WARN_STRICT_OVERFLOW_COMPARISON); - return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), - TREE_OPERAND (arg0, 1)); - } - /* For comparisons of pointers we can decompose it to a compile time comparison of the base objects and the offsets into the object. This requires at least one operand being an ADDR_EXPR or a @@ -9088,38 +9022,6 @@ fold_comparison (location_t loc, enum tr } } - /* Transform comparisons of the form X * C1 CMP 0 to X CMP 0 in the - signed arithmetic case. That form is created by the compiler - often enough for folding it to be of value. One example is in - computing loop trip counts after Operator Strength Reduction. */ - if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg0)) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0)) - && TREE_CODE (arg0) == MULT_EXPR - && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST - && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1))) - && integer_zerop (arg1)) - { - tree const1 = TREE_OPERAND (arg0, 1); - tree const2 = arg1; /* zero */ - tree variable1 = TREE_OPERAND (arg0, 0); - enum tree_code cmp_code = code; - - /* Handle unfolded multiplication by zero. */ - if (integer_zerop (const1)) - return fold_build2_loc (loc, cmp_code, type, const1, const2); - - fold_overflow_warning (("assuming signed overflow does not occur when " - "eliminating multiplication in comparison " - "with zero"), - WARN_STRICT_OVERFLOW_COMPARISON); - - /* If const1 is negative we swap the sense of the comparison. */ - if (tree_int_cst_sgn (const1) < 0) - cmp_code = swap_tree_comparison (cmp_code); - - return fold_build2_loc (loc, cmp_code, type, variable1, const2); - } - tem = maybe_canonicalize_comparison (loc, code, type, arg0, arg1); if (tem) return tem; @@ -9241,40 +9138,6 @@ fold_comparison (location_t loc, enum tr return tem; } - /* Simplify comparison of something with itself. (For IEEE - floating-point, we can only do some of these simplifications.) */ - if (operand_equal_p (arg0, arg1, 0)) - { - switch (code) - { - case EQ_EXPR: - if (! FLOAT_TYPE_P (TREE_TYPE (arg0)) - || ! HONOR_NANS (arg0)) - return constant_boolean_node (1, type); - break; - - case GE_EXPR: - case LE_EXPR: - if (! FLOAT_TYPE_P (TREE_TYPE (arg0)) - || ! HONOR_NANS (arg0)) - return constant_boolean_node (1, type); - return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg1); - - case NE_EXPR: - /* For NE, we can only do this simplification if integer - or we don't honor IEEE floating point NaNs. */ - if (FLOAT_TYPE_P (TREE_TYPE (arg0)) - && HONOR_NANS (arg0)) - break; - /* ... fall through ... */ - case GT_EXPR: - case LT_EXPR: - return constant_boolean_node (0, type); - default: - gcc_unreachable (); - } - } - /* If we are comparing an expression that just has comparisons of two integer values, arithmetic expressions of those comparisons, and constants, we can simplify it. There are only three cases @@ -9392,28 +9255,6 @@ fold_comparison (location_t loc, enum tr return tem; } - /* Fold ~X op ~Y as Y op X. */ - if (TREE_CODE (arg0) == BIT_NOT_EXPR - && TREE_CODE (arg1) == BIT_NOT_EXPR) - { - tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); - return fold_build2_loc (loc, code, type, - fold_convert_loc (loc, cmp_type, - TREE_OPERAND (arg1, 0)), - TREE_OPERAND (arg0, 0)); - } - - /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ - if (TREE_CODE (arg0) == BIT_NOT_EXPR - && (TREE_CODE (arg1) == INTEGER_CST || TREE_CODE (arg1) == VECTOR_CST)) - { - tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); - return fold_build2_loc (loc, swap_tree_comparison (code), type, - TREE_OPERAND (arg0, 0), - fold_build1_loc (loc, BIT_NOT_EXPR, cmp_type, - fold_convert_loc (loc, cmp_type, arg1))); - } - return NULL_TREE; } Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 225225) +++ gcc/match.pd (working copy) @@ -1262,6 +1262,7 @@ (define_operator_list swapped_tcc_compar == TYPE_MODE (TREE_TYPE (TREE_TYPE (@0))))) (plus @3 (view_convert @0)))) + /* Simplifications of comparisons. */ /* We can simplify a logical negation of a comparison to the @@ -1299,6 +1300,68 @@ (define_operator_list swapped_tcc_compar (if (ic == ncmp) (ncmp @0 @1))))) +/* Transform comparisons of the form X - Y CMP 0 to X CMP Y. + ??? The transformation is valid for the other operators if overflow + is undefined for the type, but performing it here badly interacts + with the transformation in fold_cond_expr_with_comparison which + attempts to synthetize ABS_EXPR. */ +(for cmp (eq ne) + (simplify + (cmp (minus @0 @1) integer_zerop) + (cmp @0 @1))) + +/* Transform comparisons of the form X * C1 CMP 0 to X CMP 0 in the + signed arithmetic case. That form is created by the compiler + often enough for folding it to be of value. One example is in + computing loop trip counts after Operator Strength Reduction. */ +(for cmp (tcc_comparison) + scmp (swapped_tcc_comparison) + (simplify + (cmp (mult @0 INTEGER_CST@1) integer_zerop@2) + /* Handle unfolded multiplication by zero. */ + (if (integer_zerop (@1)) + (cmp @1 @2)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + /* If @1 is negative we swap the sense of the comparison. */ + (if (tree_int_cst_sgn (@1) < 0) + (scmp @0 @2)) + (cmp @0 @2)))) + +/* Simplify comparison of something with itself. For IEEE + floating-point, we can only do some of these simplifications. */ +(simplify + (eq @0 @0) + (if (! FLOAT_TYPE_P (TREE_TYPE (@0)) + || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0)))) + { constant_boolean_node (true, type); })) +(for cmp (ge le) + (simplify + (cmp @0 @0) + (eq @0 @0))) +(for cmp (ne gt lt) + (simplify + (cmp @0 @0) + (if (cmp != NE_EXPR + || ! FLOAT_TYPE_P (TREE_TYPE (@0)) + || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0)))) + { constant_boolean_node (false, type); }))) + +/* Fold ~X op ~Y as Y op X. */ +(for cmp (tcc_comparison) + (simplify + (cmp (bit_not @0) (bit_not @1)) + (cmp @1 @0))) + +/* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ +(for cmp (tcc_comparison) + scmp (swapped_tcc_comparison) + (simplify + (cmp (bit_not @0) CONSTANT_CLASS_P@1) + (if (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST) + (scmp @0 (bit_not @1))))) + + /* Unordered tests if either argument is a NaN. */ (simplify (bit_ior (unordered @0 @0) (unordered @1 @1))