Commit 9737efaf by Marek Polacek Committed by Marek Polacek

match.pd ((x + y) - (x | y) -> x & y, (x + y) - (x & y) -> x | y): New patterns.

	* match.pd ((x + y) - (x | y) -> x & y,
	(x + y) - (x & y) -> x | y): New patterns.

	* 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.

From-SVN: r224834
parent 7b91cc91
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
......
......@@ -343,6 +343,20 @@ along with GCC; see the file COPYING3. If not see
(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.
......
/* { 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;
}
/* { 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" } } */
/* { 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" } } */
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