+2015-10-28 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/68067
+ * fold-const.c (negate_expr_p): We cannot negate plus or minus
+ if overflow is not wrapping. Likewise multiplication unless
+ one operand is constant and not power of two.
+ (fold_negate_expr): Adjust accordingly.
+
2015-10-27 Nathan Sidwell <nathan@codesourcery.com>
* omp-low.c (struct omp_context): Remove gwv_below, gwv_this
case PLUS_EXPR:
if (HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
- || HONOR_SIGNED_ZEROS (element_mode (type)))
+ || HONOR_SIGNED_ZEROS (element_mode (type))
+ || (INTEGRAL_TYPE_P (type)
+ && ! TYPE_OVERFLOW_WRAPS (type)))
return false;
/* -(A + B) -> (-B) - A. */
if (negate_expr_p (TREE_OPERAND (t, 1))
/* 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)
+ || TYPE_OVERFLOW_WRAPS (type))
&& reorder_operands_p (TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1));
case MULT_EXPR:
- if (TYPE_UNSIGNED (TREE_TYPE (t)))
- break;
+ if (TYPE_UNSIGNED (type))
+ break;
+ /* INT_MIN/n * n doesn't overflow while negating one operand it does
+ if n is a power of two. */
+ if (INTEGRAL_TYPE_P (TREE_TYPE (t))
+ && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
+ && ! ((TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
+ && ! integer_pow2p (TREE_OPERAND (t, 0)))
+ || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
+ && ! integer_pow2p (TREE_OPERAND (t, 1)))))
+ break;
/* Fall through. */
+2015-10-28 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/68067
+ * gcc.dg/torture/pr68067-1.c: New testcase.
+ * gcc.dg/torture/pr68067-2.c: Likewise.
+
2015-10-28 Segher Boessenkool <segher@kernel.crashing.org>
* gcc.target/powerpc/p8vector-builtin-8.c: Add "target int128".