aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-12-04 10:38:48 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-12-04 10:38:48 +0100
commit526b4c716a340ee9464965e63eee2b9954fe21f1 (patch)
tree23a2d4dc47394916d3c8e36899a6ebb0d397535b
parent6f1e966874de23d7e47cbaebfb5a9de6759cb089 (diff)
downloadgcc-526b4c716a340ee9464965e63eee2b9954fe21f1.zip
gcc-526b4c716a340ee9464965e63eee2b9954fe21f1.tar.gz
gcc-526b4c716a340ee9464965e63eee2b9954fe21f1.tar.bz2
re PR tree-optimization/92734 (Missing match.pd simplification done by fold_binary_loc on generic)
PR tree-optimization/92734 * match.pd ((A +- B) - A -> +- B, (A +- B) -+ B -> A, A - (A +- B) -> -+ B, A +- (B -+ A) -> +- B): Handle nop_convert. * gcc.dg/tree-ssa/pr92734-2.c: New test. From-SVN: r278958
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/match.pd26
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr92734-2.c76
4 files changed, 103 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e04a48a..7b518af 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/92734
+ * match.pd ((A +- B) - A -> +- B, (A +- B) -+ B -> A,
+ A - (A +- B) -> -+ B, A +- (B -+ A) -> +- B): Handle nop_convert.
+
2019-12-04 Kewen Lin <linkw@gcc.gnu.org>
PR target/92760
diff --git a/gcc/match.pd b/gcc/match.pd
index d3312e5..c50b546 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2159,20 +2159,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* A - (A +- B) -> -+ B */
/* A +- (B -+ A) -> +- B */
(simplify
- (minus (plus:c @0 @1) @0)
- @1)
+ (minus (nop_convert (plus:c (nop_convert @0) @1)) @0)
+ (view_convert @1))
(simplify
- (minus (minus @0 @1) @0)
- (negate @1))
+ (minus (nop_convert (minus (nop_convert @0) @1)) @0)
+ (if (!ANY_INTEGRAL_TYPE_P (type)
+ || TYPE_OVERFLOW_WRAPS (type))
+ (negate (view_convert @1))
+ (view_convert (negate @1))))
(simplify
- (plus:c (minus @0 @1) @1)
- @0)
+ (plus:c (nop_convert (minus @0 (nop_convert @1))) @1)
+ (view_convert @0))
(simplify
- (minus @0 (plus:c @0 @1))
- (negate @1))
+ (minus @0 (nop_convert (plus:c (nop_convert @0) @1)))
+ (if (!ANY_INTEGRAL_TYPE_P (type)
+ || TYPE_OVERFLOW_WRAPS (type))
+ (negate (view_convert @1))
+ (view_convert (negate @1))))
(simplify
- (minus @0 (minus @0 @1))
- @1)
+ (minus @0 (nop_convert (minus (nop_convert @0) @1)))
+ (view_convert @1))
/* (A +- B) + (C - A) -> C +- B */
/* (A + B) - (A - C) -> B + C */
/* More cases are handled with comparisons. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3dbf601..1d6541a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/92734
+ * gcc.dg/tree-ssa/pr92734-2.c: New test.
+
2019-12-04 Richard Sandiford <richard.sandiford@arm.com>
* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_1.C: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr92734-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr92734-2.c
new file mode 100644
index 0000000..e1b01fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr92734-2.c
@@ -0,0 +1,76 @@
+/* PR tree-optimization/92734 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* Verify there are no binary additions or subtractions left. There can
+ be just casts and negations. */
+/* { dg-final { scan-tree-dump-not " \[+-] " "optimized" } } */
+
+int
+f1 (int x, unsigned y)
+{
+ int a = x + y;
+ return a - x;
+}
+
+unsigned
+f2 (unsigned x, int y)
+{
+ unsigned a = (int) x + y;
+ return a - x;
+}
+
+int
+f3 (int x, unsigned y)
+{
+ int a = x - y;
+ return a - x;
+}
+
+unsigned
+f4 (unsigned x, int y)
+{
+ unsigned a = (int) x - y;
+ return a - x;
+}
+
+int
+f5 (unsigned x, int y)
+{
+ int a = x - y;
+ return a + y;
+}
+
+unsigned
+f6 (int x, unsigned y)
+{
+ unsigned a = x - (int) y;
+ return a + y;
+}
+
+int
+f7 (int x, unsigned y)
+{
+ int a = x + y;
+ return x - a;
+}
+
+unsigned
+f8 (unsigned x, int y)
+{
+ unsigned a = (int) x + y;
+ return x - a;
+}
+
+int
+f9 (int x, unsigned y)
+{
+ int a = x - y;
+ return x - a;
+}
+
+unsigned
+f10 (unsigned x, int y)
+{
+ unsigned a = (int) x - y;
+ return x - a;
+}