Commit 81bd903a by Marc Glisse Committed by Marc Glisse

More fold_negate in match.pd

gcc/ChangeLog:

2017-11-07  Marc Glisse  <marc.glisse@inria.fr>

	* fold-const.c (negate_expr_p) [PLUS_EXPR, MINUS_EXPR]: Handle
	non-scalar integral types.
	* match.pd (negate_expr_p): Handle MINUS_EXPR.
	(-(A-B), -(~A)): New transformations.

gcc/testsuite/ChangeLog:

2017-11-07  Marc Glisse  <marc.glisse@inria.fr>

	* gcc.dg/tree-ssa/negminus.c: New test.

From-SVN: r254494
parent 13792cce
2017-11-07 Marc Glisse <marc.glisse@inria.fr>
* fold-const.c (negate_expr_p) [PLUS_EXPR, MINUS_EXPR]: Handle
non-scalar integral types.
* match.pd (negate_expr_p): Handle MINUS_EXPR.
(-(A-B), -(~A)): New transformations.
2017-11-07 Tom de Vries <tom@codesourcery.com>
* config/powerpcspe/aix43.h (SUBTARGET_OVERRIDE_OPTIONS): Remove
......@@ -428,7 +428,7 @@ negate_expr_p (tree t)
case PLUS_EXPR:
if (HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
|| HONOR_SIGNED_ZEROS (element_mode (type))
|| (INTEGRAL_TYPE_P (type)
|| (ANY_INTEGRAL_TYPE_P (type)
&& ! TYPE_OVERFLOW_WRAPS (type)))
return false;
/* -(A + B) -> (-B) - A. */
......@@ -441,7 +441,7 @@ negate_expr_p (tree t)
/* We can't turn -(A-B) into B-A when we honor signed zeros. */
return !HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
&& !HONOR_SIGNED_ZEROS (element_mode (type))
&& (! INTEGRAL_TYPE_P (type)
&& (! ANY_INTEGRAL_TYPE_P (type)
|| TYPE_OVERFLOW_WRAPS (type));
case MULT_EXPR:
......
......@@ -958,6 +958,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(match negate_expr_p
VECTOR_CST
(if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))))
(match negate_expr_p
(minus @0 @1)
(if ((ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type))
|| (FLOAT_TYPE_P (type)
&& !HONOR_SIGN_DEPENDENT_ROUNDING (type)
&& !HONOR_SIGNED_ZEROS (type)))))
/* (-A) * (-B) -> A * B */
(simplify
......@@ -973,6 +979,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& !HONOR_SIGNED_ZEROS (element_mode (type)))
(minus (negate @1) @0)))
/* -(A - B) -> B - A. */
(simplify
(negate (minus @0 @1))
(if ((ANY_INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_SANITIZED (type))
|| (FLOAT_TYPE_P (type)
&& !HONOR_SIGN_DEPENDENT_ROUNDING (type)
&& !HONOR_SIGNED_ZEROS (type)))
(minus @1 @0)))
/* A - B -> A + (-B) if B is easily negatable. */
(simplify
(minus @0 negate_expr_p@1)
......@@ -1082,6 +1097,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
|| !TYPE_UNSIGNED (TREE_TYPE (@0)))
(convert (minus @0 { build_each_one_cst (TREE_TYPE (@0)); }))))
/* Convert - (~A) to A + 1. */
(simplify
(negate (nop_convert (bit_not @0)))
(plus (view_convert @0) { build_each_one_cst (type); }))
/* Convert ~ (A - 1) or ~ (A + -1) to -A. */
(simplify
(bit_not (convert? (minus @0 integer_each_onep)))
......
2017-11-07 Marc Glisse <marc.glisse@inria.fr>
* gcc.dg/tree-ssa/negminus.c: New test.
2017-11-06 Jeff Law <law@redhat.com>
* gcc.target/i386/stack-check-12.c: Revert to initial version. Then..
......
/* { dg-do compile } */
/* { dg-options "-O -fno-rounding-math -fno-signed-zeros -fdump-tree-optimized-raw" } */
double f(double a, double b){
double c = a - b;
return -c;
}
int g(unsigned x){
unsigned y = ~x;
int z = (int) y;
return -z;
}
unsigned h(unsigned a, unsigned b, unsigned c){
unsigned d = b - c;
unsigned e = a + d;
return -e;
}
/* { dg-final { scan-tree-dump-not "negate_expr" "optimized"} } */
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