+2013-04-11 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/56899
+ * fold-const.c (extract_muldiv_1): Apply distributive law
+ only if TYPE_OVERFLOW_WRAPS (ctype).
+
2013-04-11 Bin Cheng <bin.cheng@arm.com>
PR target/56124
/* The last case is if we are a multiply. In that case, we can
apply the distributive law to commute the multiply and addition
- if the multiplication of the constants doesn't overflow. */
- if (code == MULT_EXPR)
+ if the multiplication of the constants doesn't overflow
+ and overflow is defined. With undefined overflow
+ op0 * c might overflow, while (op0 + orig_op1) * c doesn't. */
+ if (code == MULT_EXPR && TYPE_OVERFLOW_WRAPS (ctype))
return fold_build2 (tcode, ctype,
fold_build2 (code, ctype,
fold_convert (ctype, op0),
+2013-04-11 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/56899
+ * gcc.c-torture/execute/pr56899.c: New test.
+
2013-04-10 David S. Miller <davem@davemloft.net>
* gcc.target/sparc/setcc-4.c: New test.
--- /dev/null
+/* PR tree-optimization/56899 */
+
+#if __SIZEOF_INT__ == 4 && __CHAR_BIT__ == 8
+__attribute__((noinline, noclone)) void
+f1 (int v)
+{
+ int x = -214748365 * (v - 1);
+ if (x != -1932735285)
+ __builtin_abort ();
+}
+
+__attribute__((noinline, noclone)) void
+f2 (int v)
+{
+ int x = 214748365 * (v + 1);
+ if (x != -1932735285)
+ __builtin_abort ();
+}
+
+__attribute__((noinline, noclone)) void
+f3 (unsigned int v)
+{
+ unsigned int x = -214748365U * (v - 1);
+ if (x != -1932735285U)
+ __builtin_abort ();
+}
+
+__attribute__((noinline, noclone)) void
+f4 (unsigned int v)
+{
+ unsigned int x = 214748365U * (v + 1);
+ if (x != -1932735285U)
+ __builtin_abort ();
+}
+#endif
+
+int
+main ()
+{
+#if __SIZEOF_INT__ == 4 && __CHAR_BIT__ == 8
+ f1 (10);
+ f2 (-10);
+ f3 (10);
+ f4 (-10U);
+#endif
+ return 0;
+}