+2015-06-23 Marek Polacek <polacek@redhat.com>
+
+ * match.pd ((x + y) - (x | y) -> x & y,
+ (x + y) - (x & y) -> x | y): New patterns.
+
2015-06-23 Ludovic Courtès <ludo@gnu.org>
PR 65711
(plus:c (bit_and @0 @1) (bit_ior @0 @1))
(plus @0 @1))
+/* (x + y) - (x | y) -> x & y */
+(simplify
+ (minus (plus @0 @1) (bit_ior @0 @1))
+ (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
+ && !TYPE_SATURATING (type))
+ (bit_and @0 @1)))
+
+/* (x + y) - (x & y) -> x | y */
+(simplify
+ (minus (plus @0 @1) (bit_and @0 @1))
+ (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
+ && !TYPE_SATURATING (type))
+ (bit_ior @0 @1)))
+
/* (x | y) - (x ^ y) -> x & y */
(simplify
(minus (bit_ior @0 @1) (bit_xor @0 @1))
+2015-06-23 Marek Polacek <polacek@redhat.com>
+
+ * gcc.dg/fold-minus-4.c: New test.
+ * gcc.dg/fold-minus-5.c: New test.
+ * c-c++-common/ubsan/overflow-add-5.c: New test.
+
2015-06-23 James Greenhalgh <james.greenhalgh@arm.com>
Add missing testcase from r224672.
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fsanitize=signed-integer-overflow" } */
+
+int __attribute__ ((noinline))
+foo (int i, int j)
+{
+ return (i + j) - (i | j);
+}
+
+/* { dg-output "signed integer overflow: 2147483647 \\+ 1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 2147483647 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
+
+int __attribute__ ((noinline))
+bar (int i, int j)
+{
+ return (i + j) - (i & j);
+}
+
+/* { dg-output "\[^\n\r]*signed integer overflow: 2147483647 \\+ 1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'" } */
+
+int
+main ()
+{
+ int r = foo (__INT_MAX__, 1);
+ asm volatile ("" : "+g" (r));
+ r = bar (__INT_MAX__, 1);
+ asm volatile ("" : "+g" (r));
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a + b;
+ int tem2 = a & b;
+ return tem1 - tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b + a;
+ int tem2 = a & b;
+ return tem1 - tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a + b;
+ int tem2 = b & a;
+ return tem1 - tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b + a;
+ int tem2 = b & a;
+ return tem1 - tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\+ " "cddce1" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a + b;
+ int tem2 = a | b;
+ return tem1 - tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b + a;
+ int tem2 = a | b;
+ return tem1 - tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a + b;
+ int tem2 = b | a;
+ return tem1 - tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b + a;
+ int tem2 = b | a;
+ return tem1 - tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\+ " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */