Commit 55cf3946 by Richard Biener Committed by Richard Biener

fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var and bool_var == 1…

fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var and bool_var == 1 -> bool_var simplifications ...

2015-07-15  Richard Biener  <rguenther@suse.de>

	* fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var
	and bool_var == 1 -> bool_var simplifications ...
	* match.pd: ... to patterns here.  Factor out negate_expr_p
	cases from the A - B -> A + (-B) patterns as negate_expr_p
	predicate and add a -(A + B) -> (-B) - A pattern.

From-SVN: r225825
parent aa6cf07e
2015-07-15 Richard Biener <rguenther@suse.de>
* fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var
and bool_var == 1 -> bool_var simplifications ...
* match.pd: ... to patterns here. Factor out negate_expr_p
cases from the A - B -> A + (-B) patterns as negate_expr_p
predicate and add a -(A + B) -> (-B) - A pattern.
2015-07-15 Robert Suchanek <robert.suchanek@imgtec.com> 2015-07-15 Robert Suchanek <robert.suchanek@imgtec.com>
* config/mips/mips.c (mips_emit_save_slot_move): Fix typo. * config/mips/mips.c (mips_emit_save_slot_move): Fix typo.
......
...@@ -11245,16 +11245,6 @@ fold_binary_loc (location_t loc, ...@@ -11245,16 +11245,6 @@ fold_binary_loc (location_t loc,
if (tem != NULL_TREE) if (tem != NULL_TREE)
return tem; return tem;
/* bool_var != 0 becomes bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
&& code == NE_EXPR)
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* bool_var == 1 becomes bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
&& code == EQ_EXPR)
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* bool_var != 1 becomes !bool_var. */ /* bool_var != 1 becomes !bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
&& code == NE_EXPR) && code == NE_EXPR)
......
...@@ -479,23 +479,38 @@ along with GCC; see the file COPYING3. If not see ...@@ -479,23 +479,38 @@ along with GCC; see the file COPYING3. If not see
(abs tree_expr_nonnegative_p@0) (abs tree_expr_nonnegative_p@0)
@0) @0)
/* A - B -> A + (-B) if B is easily negatable. This just covers /* A few cases of fold-const.c negate_expr_p predicate. */
very few cases of "easily negatable", effectively inlining negate_expr_p. */ (match negate_expr_p
(simplify INTEGER_CST
(minus @0 INTEGER_CST@1)
(if ((INTEGRAL_TYPE_P (type) (if ((INTEGRAL_TYPE_P (type)
&& TYPE_OVERFLOW_WRAPS (type)) && TYPE_OVERFLOW_WRAPS (type))
|| (!TYPE_OVERFLOW_SANITIZED (type) || (!TYPE_OVERFLOW_SANITIZED (type)
&& may_negate_without_overflow_p (@1))) && may_negate_without_overflow_p (t)))))
(plus @0 (negate @1)))) (match negate_expr_p
FIXED_CST)
(match negate_expr_p
(negate @0)
(if (!TYPE_OVERFLOW_SANITIZED (type))))
(match negate_expr_p
REAL_CST
(if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (t)))))
/* VECTOR_CST handling of non-wrapping types would recurse in unsupported
ways. */
(match negate_expr_p
VECTOR_CST
(if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))))
/* -(A + B) -> (-B) - A. */
(simplify (simplify
(minus @0 REAL_CST@1) (negate (plus:c @0 negate_expr_p@1))
(if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1))) (if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
(plus @0 (negate @1)))) && !HONOR_SIGNED_ZEROS (element_mode (type)))
(minus (negate @1) @0)))
/* A - B -> A + (-B) if B is easily negatable. */
(simplify (simplify
(minus @0 VECTOR_CST@1) (minus @0 negate_expr_p@1)
(if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type)) (plus @0 (negate @1)))
(plus @0 (negate @1))))
/* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)) /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST))
...@@ -1678,6 +1693,20 @@ along with GCC; see the file COPYING3. If not see ...@@ -1678,6 +1693,20 @@ along with GCC; see the file COPYING3. If not see
(if (tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0))) (if (tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0)))
(cmp @0 (bit_xor @1 (convert @2)))))) (cmp @0 (bit_xor @1 (convert @2))))))
/* bool_var != 0 becomes bool_var. */
(simplify
(ne @0 integer_zerop@1)
(if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE
&& types_match (type, TREE_TYPE (@0)))
(non_lvalue @0)))
/* bool_var == 1 becomes bool_var. */
(simplify
(eq @0 integer_onep@1)
(if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE
&& types_match (type, TREE_TYPE (@0)))
(non_lvalue @0)))
/* Simplification of math builtins. */ /* Simplification of math builtins. */
/* fold_builtin_logarithm */ /* fold_builtin_logarithm */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment