From patchwork Mon Nov 10 15:31:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 408981 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 1A606140146 for ; Tue, 11 Nov 2014 02:37:29 +1100 (AEDT) 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=VDGlczLhmglRQXTAWe3ue56SM2bS6RAe8rGEV58AymD1bvc4oltH/ KGyd+JlBgprNxJDh/2YZANtosaSCjI1WAmrf32I03eM/Kl3JWqxlA1wE4kOK9PMq MG46miaHfyI78/DVKW/rLqqQAeIlG7XMnjWPKgeY8dEXbVLEWFNijg= 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=CLQrAmcwaojfYqRTZs9ymCzofSU=; b=RM9RcoYyCKMm9Kwualmi vjbrM1KaMStB7aVmqO9HP6mJ9KYOiLf/ZfoHiRmXy7YsAHGMPD4+Rej5ieefv4t8 yb8/wedl8uLqK54UG0XcAB2iVoN5y6doLUJxNesFOQqQI0whohEnbfVuYUJDMJu7 QRio9zjn/cfRF0US7RDHcw8= Received: (qmail 3945 invoked by alias); 10 Nov 2014 15:37:22 -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 3927 invoked by uid 89); 10 Nov 2014 15:37:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham 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; Mon, 10 Nov 2014 15:37:18 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 085D7ABA3 for ; Mon, 10 Nov 2014 15:37:14 +0000 (UTC) Date: Mon, 10 Nov 2014 16:31:17 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [match-and-simplify] Remove supposedly dead code Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 "supposedly" because there are a few regressions. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-11-10 Richard Biener * tree-ssa-forwprop.c (simplify_conversion_from_bitmask): Remove. (associate_plusminus): Likewise. (combine_conversions): Likewise. (simplify_mult): Likewise. (pass_forwprop::execute): Adjust. * gimple-fold.c (fold_gimple_assign): Remove dispatches to fold_binary_loc and fold_ternary_loc. (gimple_fold_stmt_to_constant_1): Likewise. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 217279) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -1214,78 +1214,6 @@ bailout: } -/* GSI_P points to a statement which performs a narrowing integral - conversion. - - Look for cases like: - - t = x & c; - y = (T) t; - - Turn them into: - - t = x & c; - y = (T) x; - - If T is narrower than X's type and C merely masks off bits outside - of (T) and nothing else. - - Normally we'd let DCE remove the dead statement. But no DCE runs - after the last forwprop/combine pass, so we remove the obviously - dead code ourselves. - - Return TRUE if a change was made, FALSE otherwise. */ - -static bool -simplify_conversion_from_bitmask (gimple_stmt_iterator *gsi_p) -{ - gimple stmt = gsi_stmt (*gsi_p); - gimple rhs_def_stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt)); - - /* See if the input for the conversion was set via a BIT_AND_EXPR and - the only use of the BIT_AND_EXPR result is the conversion. */ - if (is_gimple_assign (rhs_def_stmt) - && gimple_assign_rhs_code (rhs_def_stmt) == BIT_AND_EXPR - && has_single_use (gimple_assign_lhs (rhs_def_stmt))) - { - tree rhs_def_operand1 = gimple_assign_rhs1 (rhs_def_stmt); - tree rhs_def_operand2 = gimple_assign_rhs2 (rhs_def_stmt); - tree lhs_type = TREE_TYPE (gimple_assign_lhs (stmt)); - - /* Now verify suitability of the BIT_AND_EXPR's operands. - The first must be an SSA_NAME that we can propagate and the - second must be an integer constant that masks out all the - bits outside the final result's type, but nothing else. */ - if (TREE_CODE (rhs_def_operand1) == SSA_NAME - && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs_def_operand1) - && TREE_CODE (rhs_def_operand2) == INTEGER_CST - && operand_equal_p (rhs_def_operand2, - build_low_bits_mask (TREE_TYPE (rhs_def_operand2), - TYPE_PRECISION (lhs_type)), - 0)) - { - /* This is an optimizable case. Replace the source operand - in the conversion with the first source operand of the - BIT_AND_EXPR. */ - gimple_assign_set_rhs1 (stmt, rhs_def_operand1); - stmt = gsi_stmt (*gsi_p); - update_stmt (stmt); - - /* There is no DCE after the last forwprop pass. It's - easy to clean up the first order effects here. */ - gimple_stmt_iterator si; - si = gsi_for_stmt (rhs_def_stmt); - gsi_remove (&si, true); - fwprop_invalidate_lattice (gimple_get_lhs (rhs_def_stmt)); - release_defs (rhs_def_stmt); - return true; - } - } - - return false; -} - - /* Helper function for simplify_gimple_switch. Remove case labels that have values outside the range of the new type. */ @@ -1992,467 +1920,6 @@ simplify_rotate (gimple_stmt_iterator *g return true; } -/* Perform re-associations of the plus or minus statement STMT that are - always permitted. Returns true if the CFG was changed. */ - -static bool -associate_plusminus (gimple_stmt_iterator *gsi) -{ - gimple stmt = gsi_stmt (*gsi); - tree rhs1 = gimple_assign_rhs1 (stmt); - tree rhs2 = gimple_assign_rhs2 (stmt); - enum tree_code code = gimple_assign_rhs_code (stmt); - bool changed; - - /* We can't reassociate at all for saturating types. */ - if (TYPE_SATURATING (TREE_TYPE (rhs1))) - return false; - - /* First contract negates. */ - do - { - changed = false; - - /* A +- (-B) -> A -+ B. */ - if (TREE_CODE (rhs2) == SSA_NAME) - { - gimple def_stmt = SSA_NAME_DEF_STMT (rhs2); - if (is_gimple_assign (def_stmt) - && gimple_assign_rhs_code (def_stmt) == NEGATE_EXPR - && can_propagate_from (def_stmt)) - { - code = (code == MINUS_EXPR) ? PLUS_EXPR : MINUS_EXPR; - gimple_assign_set_rhs_code (stmt, code); - rhs2 = gimple_assign_rhs1 (def_stmt); - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - changed = true; - } - } - - /* (-A) + B -> B - A. */ - if (TREE_CODE (rhs1) == SSA_NAME - && code == PLUS_EXPR) - { - gimple def_stmt = SSA_NAME_DEF_STMT (rhs1); - if (is_gimple_assign (def_stmt) - && gimple_assign_rhs_code (def_stmt) == NEGATE_EXPR - && can_propagate_from (def_stmt)) - { - code = MINUS_EXPR; - gimple_assign_set_rhs_code (stmt, code); - rhs1 = rhs2; - gimple_assign_set_rhs1 (stmt, rhs1); - rhs2 = gimple_assign_rhs1 (def_stmt); - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - changed = true; - } - } - } - while (changed); - - /* We can't reassociate floating-point or fixed-point plus or minus - because of saturation to +-Inf. */ - if (FLOAT_TYPE_P (TREE_TYPE (rhs1)) - || FIXED_POINT_TYPE_P (TREE_TYPE (rhs1))) - goto out; - - /* Second match patterns that allow contracting a plus-minus pair - irrespective of overflow issues. - - (A +- B) - A -> +- B - (A +- B) -+ B -> A - (CST +- A) +- CST -> CST +- A - (A +- CST) +- CST -> A +- CST - ~A + A -> -1 - ~A + 1 -> -A - A - (A +- B) -> -+ B - A +- (B +- A) -> +- B - CST +- (CST +- A) -> CST +- A - CST +- (A +- CST) -> CST +- A - A + ~A -> -1 - (T)(P + A) - (T)P -> (T)A - - via commutating the addition and contracting operations to zero - by reassociation. */ - - if (TREE_CODE (rhs1) == SSA_NAME) - { - gimple def_stmt = SSA_NAME_DEF_STMT (rhs1); - if (is_gimple_assign (def_stmt) && can_propagate_from (def_stmt)) - { - enum tree_code def_code = gimple_assign_rhs_code (def_stmt); - if (def_code == PLUS_EXPR - || def_code == MINUS_EXPR) - { - tree def_rhs1 = gimple_assign_rhs1 (def_stmt); - tree def_rhs2 = gimple_assign_rhs2 (def_stmt); - if (operand_equal_p (def_rhs1, rhs2, 0) - && code == MINUS_EXPR) - { - /* (A +- B) - A -> +- B. */ - code = ((def_code == PLUS_EXPR) - ? TREE_CODE (def_rhs2) : NEGATE_EXPR); - rhs1 = def_rhs2; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - else if (operand_equal_p (def_rhs2, rhs2, 0) - && code != def_code) - { - /* (A +- B) -+ B -> A. */ - code = TREE_CODE (def_rhs1); - rhs1 = def_rhs1; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - else if (CONSTANT_CLASS_P (rhs2) - && CONSTANT_CLASS_P (def_rhs1)) - { - /* (CST +- A) +- CST -> CST +- A. */ - tree cst = fold_binary (code, TREE_TYPE (rhs1), - def_rhs1, rhs2); - if (cst && !TREE_OVERFLOW (cst)) - { - code = def_code; - gimple_assign_set_rhs_code (stmt, code); - rhs1 = cst; - gimple_assign_set_rhs1 (stmt, rhs1); - rhs2 = def_rhs2; - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - } - } - else if (CONSTANT_CLASS_P (rhs2) - && CONSTANT_CLASS_P (def_rhs2)) - { - /* (A +- CST) +- CST -> A +- CST. */ - enum tree_code mix = (code == def_code) - ? PLUS_EXPR : MINUS_EXPR; - tree cst = fold_binary (mix, TREE_TYPE (rhs1), - def_rhs2, rhs2); - if (cst && !TREE_OVERFLOW (cst)) - { - code = def_code; - gimple_assign_set_rhs_code (stmt, code); - rhs1 = def_rhs1; - gimple_assign_set_rhs1 (stmt, rhs1); - rhs2 = cst; - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - } - } - } - else if (def_code == BIT_NOT_EXPR && code == PLUS_EXPR) - { - tree def_rhs1 = gimple_assign_rhs1 (def_stmt); - if (operand_equal_p (def_rhs1, rhs2, 0)) - { - /* ~A + A -> -1. */ - rhs1 = build_all_ones_cst (TREE_TYPE (rhs2)); - rhs2 = NULL_TREE; - code = TREE_CODE (rhs1); - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - else if ((TREE_CODE (TREE_TYPE (rhs2)) != COMPLEX_TYPE - && integer_onep (rhs2)) - || (TREE_CODE (rhs2) == COMPLEX_CST - && integer_onep (TREE_REALPART (rhs2)) - && integer_onep (TREE_IMAGPART (rhs2)))) - { - /* ~A + 1 -> -A. */ - code = NEGATE_EXPR; - rhs1 = def_rhs1; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - } - else if (code == MINUS_EXPR - && CONVERT_EXPR_CODE_P (def_code) - && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME - && TREE_CODE (rhs2) == SSA_NAME) - { - /* (T)(P + A) - (T)P -> (T)A. */ - gimple def_stmt2 = SSA_NAME_DEF_STMT (rhs2); - if (is_gimple_assign (def_stmt2) - && can_propagate_from (def_stmt2) - && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt2)) - && TREE_CODE (gimple_assign_rhs1 (def_stmt2)) == SSA_NAME) - { - /* Now we have (T)X - (T)P. */ - tree p = gimple_assign_rhs1 (def_stmt2); - def_stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (def_stmt)); - if (is_gimple_assign (def_stmt2) - && can_propagate_from (def_stmt2) - && (gimple_assign_rhs_code (def_stmt2) == POINTER_PLUS_EXPR - || gimple_assign_rhs_code (def_stmt2) == PLUS_EXPR) - && gimple_assign_rhs1 (def_stmt2) == p) - { - /* And finally (T)(P + A) - (T)P. */ - tree a = gimple_assign_rhs2 (def_stmt2); - if (TYPE_PRECISION (TREE_TYPE (rhs1)) - <= TYPE_PRECISION (TREE_TYPE (a)) - /* For integer types, if A has a smaller type - than T the result depends on the possible - overflow in P + A. - E.g. T=size_t, A=(unsigned)429497295, P>0. - However, if an overflow in P + A would cause - undefined behavior, we can assume that there - is no overflow. */ - || (INTEGRAL_TYPE_P (TREE_TYPE (p)) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (p))) - /* For pointer types, if the conversion of A to the - final type requires a sign- or zero-extension, - then we have to punt - it is not defined which - one is correct. */ - || (POINTER_TYPE_P (TREE_TYPE (p)) - && TREE_CODE (a) == INTEGER_CST - && tree_int_cst_sign_bit (a) == 0)) - { - if (issue_strict_overflow_warning - (WARN_STRICT_OVERFLOW_MISC) - && TYPE_PRECISION (TREE_TYPE (rhs1)) - > TYPE_PRECISION (TREE_TYPE (a)) - && INTEGRAL_TYPE_P (TREE_TYPE (p))) - warning_at (gimple_location (stmt), - OPT_Wstrict_overflow, - "assuming signed overflow does not " - "occur when assuming that " - "(T)(P + A) - (T)P is always (T)A"); - if (useless_type_conversion_p (TREE_TYPE (rhs1), - TREE_TYPE (a))) - code = TREE_CODE (a); - else - code = NOP_EXPR; - rhs1 = a; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, - rhs2); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - } - } - } - } - } - - if (rhs2 && TREE_CODE (rhs2) == SSA_NAME) - { - gimple def_stmt = SSA_NAME_DEF_STMT (rhs2); - if (is_gimple_assign (def_stmt) && can_propagate_from (def_stmt)) - { - enum tree_code def_code = gimple_assign_rhs_code (def_stmt); - if (def_code == PLUS_EXPR - || def_code == MINUS_EXPR) - { - tree def_rhs1 = gimple_assign_rhs1 (def_stmt); - tree def_rhs2 = gimple_assign_rhs2 (def_stmt); - if (operand_equal_p (def_rhs1, rhs1, 0) - && code == MINUS_EXPR) - { - /* A - (A +- B) -> -+ B. */ - code = ((def_code == PLUS_EXPR) - ? NEGATE_EXPR : TREE_CODE (def_rhs2)); - rhs1 = def_rhs2; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - else if (operand_equal_p (def_rhs2, rhs1, 0) - && code != def_code) - { - /* A +- (B +- A) -> +- B. */ - code = ((code == PLUS_EXPR) - ? TREE_CODE (def_rhs1) : NEGATE_EXPR); - rhs1 = def_rhs1; - rhs2 = NULL_TREE; - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - else if (CONSTANT_CLASS_P (rhs1) - && CONSTANT_CLASS_P (def_rhs1)) - { - /* CST +- (CST +- A) -> CST +- A. */ - tree cst = fold_binary (code, TREE_TYPE (rhs2), - rhs1, def_rhs1); - if (cst && !TREE_OVERFLOW (cst)) - { - code = (code == def_code ? PLUS_EXPR : MINUS_EXPR); - gimple_assign_set_rhs_code (stmt, code); - rhs1 = cst; - gimple_assign_set_rhs1 (stmt, rhs1); - rhs2 = def_rhs2; - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - } - } - else if (CONSTANT_CLASS_P (rhs1) - && CONSTANT_CLASS_P (def_rhs2)) - { - /* CST +- (A +- CST) -> CST +- A. */ - tree cst = fold_binary (def_code == code - ? PLUS_EXPR : MINUS_EXPR, - TREE_TYPE (rhs2), - rhs1, def_rhs2); - if (cst && !TREE_OVERFLOW (cst)) - { - rhs1 = cst; - gimple_assign_set_rhs1 (stmt, rhs1); - rhs2 = def_rhs1; - gimple_assign_set_rhs2 (stmt, rhs2); - gimple_set_modified (stmt, true); - } - } - } - else if (def_code == BIT_NOT_EXPR) - { - tree def_rhs1 = gimple_assign_rhs1 (def_stmt); - if (code == PLUS_EXPR - && operand_equal_p (def_rhs1, rhs1, 0)) - { - /* A + ~A -> -1. */ - rhs1 = build_all_ones_cst (TREE_TYPE (rhs1)); - rhs2 = NULL_TREE; - code = TREE_CODE (rhs1); - gimple_assign_set_rhs_with_ops (gsi, code, rhs1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - gimple_set_modified (stmt, true); - } - } - } - } - -out: - if (gimple_modified_p (stmt)) - { - fold_stmt_inplace (gsi); - update_stmt (stmt); - return true; - } - - return false; -} - -/* Combine two conversions in a row for the second conversion at *GSI. - Returns 1 if there were any changes made, 2 if cfg-cleanup needs to - run. Else it returns 0. */ - -static int -combine_conversions (gimple_stmt_iterator *gsi) -{ - gimple stmt = gsi_stmt (*gsi); - gimple def_stmt; - tree op0, lhs; - enum tree_code code = gimple_assign_rhs_code (stmt); - enum tree_code code2; - - gcc_checking_assert (CONVERT_EXPR_CODE_P (code) - || code == FLOAT_EXPR - || code == FIX_TRUNC_EXPR); - - lhs = gimple_assign_lhs (stmt); - op0 = gimple_assign_rhs1 (stmt); - if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (op0))) - { - gimple_assign_set_rhs_code (stmt, TREE_CODE (op0)); - return 1; - } - - if (TREE_CODE (op0) != SSA_NAME) - return 0; - - def_stmt = SSA_NAME_DEF_STMT (op0); - if (!is_gimple_assign (def_stmt)) - return 0; - - code2 = gimple_assign_rhs_code (def_stmt); - - if (CONVERT_EXPR_CODE_P (code2) || code2 == FLOAT_EXPR) - { - tree defop0 = gimple_assign_rhs1 (def_stmt); - tree type = TREE_TYPE (lhs); - tree inside_type = TREE_TYPE (defop0); - tree inter_type = TREE_TYPE (op0); - int inside_int = INTEGRAL_TYPE_P (inside_type); - unsigned int inside_prec = TYPE_PRECISION (inside_type); - int inside_unsignedp = TYPE_UNSIGNED (inside_type); - int inter_int = INTEGRAL_TYPE_P (inter_type); - int inter_float = FLOAT_TYPE_P (inter_type); - unsigned int inter_prec = TYPE_PRECISION (inter_type); - int inter_unsignedp = TYPE_UNSIGNED (inter_type); - int final_int = INTEGRAL_TYPE_P (type); - unsigned int final_prec = TYPE_PRECISION (type); - - /* Don't propagate ssa names that occur in abnormal phis. */ - if (TREE_CODE (defop0) == SSA_NAME - && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (defop0)) - return 0; - - /* A truncation to an unsigned type should be canonicalized as - bitwise and of a mask. */ - if (final_int && inter_int && inside_int - && final_prec == inside_prec - && final_prec > inter_prec - && inter_unsignedp) - { - tree tem; - tem = fold_build2 (BIT_AND_EXPR, inside_type, - defop0, - wide_int_to_tree - (inside_type, - wi::mask (inter_prec, false, - TYPE_PRECISION (inside_type)))); - if (!useless_type_conversion_p (type, inside_type)) - { - tem = force_gimple_operand_gsi (gsi, tem, true, NULL_TREE, true, - GSI_SAME_STMT); - gimple_assign_set_rhs1 (stmt, tem); - } - else - gimple_assign_set_rhs_from_tree (gsi, tem); - update_stmt (gsi_stmt (*gsi)); - return 1; - } - - /* If we are converting an integer to a floating-point that can - represent it exactly and back to an integer, we can skip the - floating-point conversion. */ - if (inside_int && inter_float && final_int && - (unsigned) significand_size (TYPE_MODE (inter_type)) - >= inside_prec - !inside_unsignedp) - { - if (useless_type_conversion_p (type, inside_type)) - { - gimple_assign_set_rhs1 (stmt, unshare_expr (defop0)); - gimple_assign_set_rhs_code (stmt, TREE_CODE (defop0)); - update_stmt (stmt); - return remove_prop_source_from_use (op0) ? 2 : 1; - } - else - { - gimple_assign_set_rhs1 (stmt, defop0); - gimple_assign_set_rhs_code (stmt, CONVERT_EXPR); - update_stmt (stmt); - return remove_prop_source_from_use (op0) ? 2 : 1; - } - } - } - - return 0; -} - /* Combine an element access with a shuffle. Returns true if there were any changes made, else it returns false. */ @@ -2768,54 +2235,6 @@ simplify_vector_constructor (gimple_stmt return true; } -/* Simplify multiplications. - Return true if a transformation applied, otherwise return false. */ - -static bool -simplify_mult (gimple_stmt_iterator *gsi) -{ - gimple stmt = gsi_stmt (*gsi); - tree arg1 = gimple_assign_rhs1 (stmt); - tree arg2 = gimple_assign_rhs2 (stmt); - - if (TREE_CODE (arg1) != SSA_NAME) - return false; - - gimple def_stmt = SSA_NAME_DEF_STMT (arg1); - if (!is_gimple_assign (def_stmt)) - return false; - - /* Look through a sign-changing conversion. */ - if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) - { - if (TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (def_stmt))) - != TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (def_stmt))) - || TREE_CODE (gimple_assign_rhs1 (def_stmt)) != SSA_NAME) - return false; - def_stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (def_stmt)); - if (!is_gimple_assign (def_stmt)) - return false; - } - - if (gimple_assign_rhs_code (def_stmt) == EXACT_DIV_EXPR) - { - if (operand_equal_p (gimple_assign_rhs2 (def_stmt), arg2, 0)) - { - tree res = gimple_assign_rhs1 (def_stmt); - if (useless_type_conversion_p (TREE_TYPE (arg1), TREE_TYPE (res))) - gimple_assign_set_rhs_with_ops (gsi, TREE_CODE (res), res, - NULL_TREE); - else - gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, res, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - update_stmt (stmt); - return true; - } - } - - return false; -} - /* Primitive "lattice" function for gimple_simplify. */ @@ -3033,48 +2452,6 @@ pass_forwprop::execute (function *fun) || code == BIT_XOR_EXPR) && simplify_rotate (&gsi)) changed = true; - else if (code == MULT_EXPR) - { - changed = simplify_mult (&gsi); - if (changed - && maybe_clean_or_replace_eh_stmt (stmt, stmt)) - bitmap_set_bit (to_purge, bb->index); - } - else if (code == PLUS_EXPR - || code == MINUS_EXPR) - { - changed = associate_plusminus (&gsi); - if (changed - && maybe_clean_or_replace_eh_stmt (stmt, stmt)) - bitmap_set_bit (to_purge, bb->index); - } - else if (CONVERT_EXPR_CODE_P (code) - || code == FLOAT_EXPR - || code == FIX_TRUNC_EXPR) - { - int did_something = combine_conversions (&gsi); - if (did_something == 2) - cfg_changed = true; - - /* If we have a narrowing conversion to an integral - type that is fed by a BIT_AND_EXPR, we might be - able to remove the BIT_AND_EXPR if it merely - masks off bits outside the final type (and nothing - else. */ - if (! did_something) - { - tree outer_type = TREE_TYPE (gimple_assign_lhs (stmt)); - tree inner_type = TREE_TYPE (gimple_assign_rhs1 (stmt)); - if (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME - && INTEGRAL_TYPE_P (outer_type) - && INTEGRAL_TYPE_P (inner_type) - && (TYPE_PRECISION (outer_type) - <= TYPE_PRECISION (inner_type))) - did_something = simplify_conversion_from_bitmask (&gsi); - } - - changed = did_something != 0; - } else if (code == VEC_PERM_EXPR) { int did_something = simplify_permutation (&gsi); Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 217279) +++ gcc/gimple-fold.c (working copy) @@ -465,12 +465,6 @@ fold_gimple_assign (gimple_stmt_iterator } } - if (!result) - result = fold_binary_loc (loc, subcode, - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt)); - if (result) { STRIP_USELESS_TYPE_CONVERSION (result); @@ -480,56 +474,6 @@ fold_gimple_assign (gimple_stmt_iterator break; case GIMPLE_TERNARY_RHS: - /* Try to fold a conditional expression. */ - if (gimple_assign_rhs_code (stmt) == COND_EXPR) - { - tree op0 = gimple_assign_rhs1 (stmt); - tree tem; - bool set = false; - location_t cond_loc = gimple_location (stmt); - - if (COMPARISON_CLASS_P (op0)) - { - fold_defer_overflow_warnings (); - tem = fold_binary_loc (cond_loc, - TREE_CODE (op0), TREE_TYPE (op0), - TREE_OPERAND (op0, 0), - TREE_OPERAND (op0, 1)); - /* This is actually a conditional expression, not a GIMPLE - conditional statement, however, the valid_gimple_rhs_p - test still applies. */ - set = (tem && is_gimple_condexpr (tem) - && valid_gimple_rhs_p (tem)); - fold_undefer_overflow_warnings (set, stmt, 0); - } - else if (is_gimple_min_invariant (op0)) - { - tem = op0; - set = true; - } - else - return NULL_TREE; - - if (set) - result = fold_build3_loc (cond_loc, COND_EXPR, - TREE_TYPE (gimple_assign_lhs (stmt)), tem, - gimple_assign_rhs2 (stmt), - gimple_assign_rhs3 (stmt)); - } - - if (!result) - result = fold_ternary_loc (loc, subcode, - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt), - gimple_assign_rhs3 (stmt)); - - if (result) - { - STRIP_USELESS_TYPE_CONVERSION (result); - if (valid_gimple_rhs_p (result)) - return result; - } break; case GIMPLE_INVALID_RHS: @@ -4528,33 +4472,11 @@ gimple_fold_stmt_to_constant_1 (gimple s unshare_expr (op0), off)); } - return fold_binary_loc (loc, subcode, - gimple_expr_type (stmt), op0, op1); + return NULL_TREE; } case GIMPLE_TERNARY_RHS: - { - /* Handle ternary operators that can appear in GIMPLE form. */ - tree op0 = (*valueize) (gimple_assign_rhs1 (stmt)); - tree op1 = (*valueize) (gimple_assign_rhs2 (stmt)); - tree op2 = (*valueize) (gimple_assign_rhs3 (stmt)); - - /* Fold embedded expressions in ternary codes. */ - if ((subcode == COND_EXPR - || subcode == VEC_COND_EXPR) - && COMPARISON_CLASS_P (op0)) - { - tree op00 = (*valueize) (TREE_OPERAND (op0, 0)); - tree op01 = (*valueize) (TREE_OPERAND (op0, 1)); - tree tem = fold_binary_loc (loc, TREE_CODE (op0), - TREE_TYPE (op0), op00, op01); - if (tem) - op0 = tem; - } - - return fold_ternary_loc (loc, subcode, - gimple_expr_type (stmt), op0, op1, op2); - } + return NULL_TREE; default: gcc_unreachable ();