diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a9978bca01643c21252cd5f6e6397ba70af12768..ee04a8606804356d4f80413fb1b051d5c454d23f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-05-18 Marc Glisse <marc.glisse@inria.fr> + + * fold-const.c (fold_binary_loc): Move transformation... + * match.pd (C - X CMP X): ... here. + 2017-05-18 Sheldon Lobo <sheldon.lobo@oracle.com> * config/sparc/sparc.c (sparc_option_override): Set function diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f6d5af43b33a8141fbb93bcae537eebed6959a6c..19aa72258497b710385ce9c456614e97b4a481a8 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10532,30 +10532,6 @@ fold_binary_loc (location_t loc, TREE_OPERAND (arg1, 0), arg0); } - /* Transform comparisons of the form C - X CMP X if C % 2 == 1. */ - if (TREE_CODE (arg0) == MINUS_EXPR - && TREE_CODE (TREE_OPERAND (arg0, 0)) == INTEGER_CST - && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0, - 1)), - arg1, 0) - && wi::extract_uhwi (TREE_OPERAND (arg0, 0), 0, 1) == 1) - return omit_two_operands_loc (loc, type, - code == NE_EXPR - ? boolean_true_node : boolean_false_node, - TREE_OPERAND (arg0, 1), arg1); - - /* Transform comparisons of the form X CMP C - X if C % 2 == 1. */ - if (TREE_CODE (arg1) == MINUS_EXPR - && TREE_CODE (TREE_OPERAND (arg1, 0)) == INTEGER_CST - && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg1, - 1)), - arg0, 0) - && wi::extract_uhwi (TREE_OPERAND (arg1, 0), 0, 1) == 1) - return omit_two_operands_loc (loc, type, - code == NE_EXPR - ? boolean_true_node : boolean_false_node, - TREE_OPERAND (arg1, 1), arg0); - /* If this is an EQ or NE comparison with zero and ARG0 is (1 << foo) & bar, convert it to (bar >> foo) & 1. Both require two operations, but the latter can be done in one less insn diff --git a/gcc/match.pd b/gcc/match.pd index 80a17ba3d23ac9c4a679085640a52b287e6f1a3a..ba501498cdd7724621455b7cb4f1d4996020e2ae 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1090,6 +1090,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) (op @1 @0)))) +/* X == C - X can never be true if C is odd. */ +(for cmp (eq ne) + (simplify + (cmp:c (convert? @0) (convert1? (minus INTEGER_CST@1 (convert2? @0)))) + (if (TREE_INT_CST_LOW (@1) & 1) + { constant_boolean_node (cmp == NE_EXPR, type); }))) + /* ((X inner_op C0) outer_op C1) With X being a tree where value_range has reasoned certain bits to always be zero throughout its computed value range,