+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
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. */
/* 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:
(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
&& !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)
|| !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..
--- /dev/null
+/* { 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"} } */