From patchwork Thu Jul 28 09:21:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 107217 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 B5293B6F64 for ; Thu, 28 Jul 2011 19:22:12 +1000 (EST) Received: (qmail 16828 invoked by alias); 28 Jul 2011 09:22:05 -0000 Received: (qmail 16818 invoked by uid 22791); 28 Jul 2011 09:22:02 -0000 X-SWARE-Spam-Status: No, hits=-7.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx3-phx2.redhat.com (HELO mx3-phx2.redhat.com) (209.132.183.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Jul 2011 09:21:40 +0000 Received: from mail06.corp.redhat.com (zmail06.collab.prod.int.phx2.redhat.com [10.5.5.45]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6S9LdkQ031566; Thu, 28 Jul 2011 05:21:39 -0400 Date: Thu, 28 Jul 2011 05:21:39 -0400 (EDT) From: Kai Tietz To: gcc-patches@gcc.gnu.org Cc: Richard Guenther Message-ID: <1185642033.312067.1311844899117.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> Subject: [patch tree-optimization]: Remove TRUTH_NOT from vrp and adjust 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 Hello, this patch removes the handling for TRUTH_NOT_EXPR in tree-vrp.c and adjust some simplifications to be compatible with BIT_NOT_EXPR. ChangeLog 2011-07-28 Kai Tietz * tree-vrp.c (simplify_stmt_using_ranges): Remove TRUTH_NOT_EXPR case. (simplify_truth_ops_using_ranges): Likewise. (build_assert_expr_for): Remove TRUTH_NOT_EXPR case and handle BIT_NOT_EXPR for truth-operation. (build_assert_expr_for_1): Likewise. Bootstrapped and regression-tested for all languages (+ Ada, Obj-C++) on host x86_64-pc-linux-gnu. Ok for apply? Regards, Kai Index: gcc-head/gcc/tree-vrp.c =================================================================== --- gcc-head.orig/gcc/tree-vrp.c +++ gcc-head/gcc/tree-vrp.c @@ -3972,7 +3972,8 @@ build_assert_expr_for (tree cond, tree v tree a = build2 (ASSERT_EXPR, TREE_TYPE (v), v, cond); assertion = gimple_build_assign (n, a); } - else if (TREE_CODE (cond) == TRUTH_NOT_EXPR) + else if (TREE_CODE (cond) == BIT_NOT_EXPR + && TYPE_PRECISION (TREE_TYPE (cond)) == 1) { /* Given !V, build the assignment N = false. */ tree op0 = TREE_OPERAND (cond, 0); @@ -4525,7 +4526,8 @@ register_edge_assert_for_1 (tree op, enu retval |= register_edge_assert_for_1 (gimple_assign_rhs2 (op_def), code, e, bsi); } - else if (gimple_assign_rhs_code (op_def) == TRUTH_NOT_EXPR) + else if (gimple_assign_rhs_code (op_def) == BIT_NOT_EXPR + && TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (op_def))) == 1) { /* Recurse, flipping CODE. */ code = invert_tree_comparison (code, false); @@ -6754,6 +6756,9 @@ simplify_truth_ops_using_ranges (gimple_ bool sop = false; bool need_conversion; + /* We handle only !=/== case here. */ + gcc_assert (rhs_code == EQ_EXPR || rhs_code == NE_EXPR); + op0 = gimple_assign_rhs1 (stmt); if (TYPE_PRECISION (TREE_TYPE (op0)) != 1) { @@ -6770,52 +6775,40 @@ simplify_truth_ops_using_ranges (gimple_ return false; } - if (rhs_code == TRUTH_NOT_EXPR) + op1 = gimple_assign_rhs2 (stmt); + + /* Reduce number of cases to handle. */ + if (is_gimple_min_invariant (op1)) { - rhs_code = NE_EXPR; - op1 = build_int_cst (TREE_TYPE (op0), 1); + if (!integer_zerop (op1) + && !integer_onep (op1) + && !integer_all_onesp (op1)) + return false; + + /* Limit the number of cases we have to consider. */ + if (rhs_code == EQ_EXPR) + { + rhs_code = NE_EXPR; + /* OP1 is a constant. */ + op1 = fold_unary (TRUTH_NOT_EXPR, TREE_TYPE (op1), op1); + } } else { - op1 = gimple_assign_rhs2 (stmt); + /* Punt on A == B as there is no BIT_XNOR_EXPR. */ + if (rhs_code == EQ_EXPR) + return false; - /* Reduce number of cases to handle. */ - if (is_gimple_min_invariant (op1)) + if (TYPE_PRECISION (TREE_TYPE (op1)) != 1) { - /* Exclude anything that should have been already folded. */ - if (rhs_code != EQ_EXPR - && rhs_code != NE_EXPR) + vr = get_value_range (op1); + val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, &sop); + if (!val || !integer_onep (val)) return false; - if (!integer_zerop (op1) - && !integer_onep (op1) - && !integer_all_onesp (op1)) + val = compare_range_with_value (LE_EXPR, vr, integer_one_node, &sop); + if (!val || !integer_onep (val)) return false; - - /* Limit the number of cases we have to consider. */ - if (rhs_code == EQ_EXPR) - { - rhs_code = NE_EXPR; - op1 = fold_unary (TRUTH_NOT_EXPR, TREE_TYPE (op1), op1); - } - } - else - { - /* Punt on A == B as there is no BIT_XNOR_EXPR. */ - if (rhs_code == EQ_EXPR) - return false; - - if (TYPE_PRECISION (TREE_TYPE (op1)) != 1) - { - vr = get_value_range (op1); - val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, &sop); - if (!val || !integer_onep (val)) - return false; - - val = compare_range_with_value (LE_EXPR, vr, integer_one_node, &sop); - if (!val || !integer_onep (val)) - return false; - } } } @@ -7514,11 +7507,9 @@ simplify_stmt_using_ranges (gimple_stmt_ { case EQ_EXPR: case NE_EXPR: - case TRUTH_NOT_EXPR: - /* Transform EQ_EXPR, NE_EXPR, TRUTH_NOT_EXPR into BIT_XOR_EXPR - or identity if the RHS is zero or one, and the LHS are known - to be boolean values. Transform all TRUTH_*_EXPR into - BIT_*_EXPR if both arguments are known to be boolean values. */ + /* Transform EQ_EXPR, NE_EXPR into BIT_XOR_EXPR or identity + if the RHS is zero or one, and the LHS are known to be boolean + values. */ if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))) return simplify_truth_ops_using_ranges (gsi, stmt); break;