From 36a60e48f4eac678cdcf0c59c0f01b9f58c7d900 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 30 Oct 2014 13:13:35 +0000 Subject: [PATCH] match.pd: Implement more patterns that simplify to a single value. 2014-10-30 Richard Biener * match.pd: Implement more patterns that simplify to a single value. * fold-const.c (fold_binary_loc): Remove them here. * tree-ssa-forwprop.c (simplify_bitwise_binary): Likewise. (fwprop_ssa_val): Remove restriction on single uses. From-SVN: r216933 --- gcc/ChangeLog | 7 +++++++ gcc/fold-const.c | 11 ----------- gcc/match.pd | 18 +++++++++++++++++- gcc/tree-ssa-forwprop.c | 18 +++--------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 58e6cd01a64..a123f9599fe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-10-30 Richard Biener + + * match.pd: Implement more patterns that simplify to a single value. + * fold-const.c (fold_binary_loc): Remove them here. + * tree-ssa-forwprop.c (simplify_bitwise_binary): Likewise. + (fwprop_ssa_val): Remove restriction on single uses. + 2014-10-30 Jan-Benedict Glaw * config/avr/driver-avr.c (avr_set_current_device): Remove. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9b9754db7bc..62582954547 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11089,9 +11089,6 @@ fold_binary_loc (location_t loc, case BIT_IOR_EXPR: bit_ior: - if (operand_equal_p (arg0, arg1, 0)) - return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - /* ~X | X is -1. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) @@ -11227,9 +11224,6 @@ fold_binary_loc (location_t loc, goto bit_rotate; case BIT_XOR_EXPR: - if (integer_all_onesp (arg1)) - return fold_build1_loc (loc, BIT_NOT_EXPR, type, op0); - /* ~X ^ X is -1. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) @@ -11384,11 +11378,6 @@ fold_binary_loc (location_t loc, goto bit_rotate; case BIT_AND_EXPR: - if (integer_all_onesp (arg1)) - return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - if (operand_equal_p (arg0, arg1, 0)) - return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - /* ~X & X, (X == 0) & X, and !X & X are always zero. */ if ((TREE_CODE (arg0) == BIT_NOT_EXPR || TREE_CODE (arg0) == TRUTH_NOT_EXPR diff --git a/gcc/match.pd b/gcc/match.pd index e9571d158a5..2057dccba46 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -31,7 +31,7 @@ along with GCC; see the file COPYING3. If not see /* Simplifications of operations with one constant operand and - simplifications to constants. */ + simplifications to constants or single values. */ (for op (plus pointer_plus minus bit_ior bit_xor) (simplify @@ -88,6 +88,22 @@ along with GCC; see the file COPYING3. If not see (bit_xor @0 @0) { build_zero_cst (type); }) +/* Canonicalize X ^ ~0 to ~X. */ +(simplify + (bit_xor @0 integer_all_onesp@1) + (bit_not @0)) + +/* x & ~0 -> x */ +(simplify + (bit_and @0 integer_all_onesp) + (non_lvalue @0)) + +/* x & x -> x, x | x -> x */ +(for bitop (bit_and bit_ior) + (simplify + (bitop @0 @0) + (non_lvalue @0))) + /* Simplifications of conversions. */ diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index a5283a2b34c..d67a4b648af 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -2097,16 +2097,6 @@ simplify_bitwise_binary (gimple_stmt_iterator *gsi) return true; } - /* Canonicalize X ^ ~0 to ~X. */ - if (code == BIT_XOR_EXPR - && integer_all_onesp (arg2)) - { - gimple_assign_set_rhs_with_ops (gsi, BIT_NOT_EXPR, arg1, NULL_TREE); - gcc_assert (gsi_stmt (*gsi) == stmt); - update_stmt (stmt); - return true; - } - /* Try simple folding for X op !X, and X op X. */ res = simplify_bitwise_binary_1 (code, TREE_TYPE (arg1), arg1, arg2); if (res != NULL_TREE) @@ -3554,11 +3544,9 @@ fwprop_ssa_val (tree name) if (val) name = val; } - /* If NAME is not the only use signal we don't want to continue - matching into its definition. */ - if (TREE_CODE (name) == SSA_NAME - && !has_single_use (name)) - return NULL_TREE; + /* We continue matching along SSA use-def edges for SSA names + that are not single-use. Currently there are no patterns + that would cause any issues with that. */ return name; } -- 2.30.2