aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-09-22 20:56:23 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2017-09-22 20:56:23 +0200
commita93952d2bee108c94f802aa14be0348bcf4bcb29 (patch)
tree849d3a7452f4b4b9d765e628ec63a4a5f3f199f4 /gcc
parent2dc589be3cb487eda8f537c535cab0f5a9a4a6a1 (diff)
downloadgcc-a93952d2bee108c94f802aa14be0348bcf4bcb29.zip
gcc-a93952d2bee108c94f802aa14be0348bcf4bcb29.tar.gz
gcc-a93952d2bee108c94f802aa14be0348bcf4bcb29.tar.bz2
re PR middle-end/35691 (Missed (a == 0) && (b == 0) into (a|(typeof(a)(b)) == 0 when the types don't match)
PR middle-end/35691 * match.pd: Simplify x == -1 & y == -1 into (x & y) == -1 and x != -1 | y != -1 into (x & y) != -1. * gcc.dg/pr35691-1.c: Use -fdump-tree-forwprop1-details instead of -fdump-tree-forwprop-details in dg-options. * gcc.dg/pr35691-2.c: Likewise. * gcc.dg/pr35691-3.c: New test. * gcc.dg/pr35691-4.c: New test. From-SVN: r253107
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/match.pd21
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/pr35691-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr35691-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr35691-3.c12
-rw-r--r--gcc/testsuite/gcc.dg/pr35691-4.c12
7 files changed, 54 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index efa98cf..af92ec3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-09-22 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/35691
+ * match.pd: Simplify x == -1 & y == -1 into (x & y) == -1
+ and x != -1 | y != -1 into (x & y) != -1.
+
2017-09-22 Steve Ellcey <sellcey@cavium.com>
* config.gcc: Add new case statement to set
diff --git a/gcc/match.pd b/gcc/match.pd
index e9017e4..0863273 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -630,17 +630,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (TYPE_UNSIGNED (type))
(bit_and @0 (bit_not (lshift { build_all_ones_cst (type); } @1)))))
-/* PR35691: Transform
- (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0.
- (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. */
(for bitop (bit_and bit_ior)
cmp (eq ne)
+ /* PR35691: Transform
+ (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0.
+ (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. */
(simplify
(bitop (cmp @0 integer_zerop@2) (cmp @1 integer_zerop))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
- && INTEGRAL_TYPE_P (TREE_TYPE (@1))
- && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
- (cmp (bit_ior @0 (convert @1)) @2))))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@1))
+ && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
+ (cmp (bit_ior @0 (convert @1)) @2)))
+ /* Transform:
+ (x == -1 & y == -1) -> (x & typeof(x)(y)) == -1.
+ (x != -1 | y != -1) -> (x & typeof(x)(y)) != -1. */
+ (simplify
+ (bitop (cmp @0 integer_all_onesp@2) (cmp @1 integer_all_onesp))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@1))
+ && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
+ (cmp (bit_and @0 (convert @1)) @2))))
/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
(simplify
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7c51045..6bdfdfe 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,12 @@
2017-09-22 Jakub Jelinek <jakub@redhat.com>
+ PR middle-end/35691
+ * gcc.dg/pr35691-1.c: Use -fdump-tree-forwprop1-details
+ instead of -fdump-tree-forwprop-details in dg-options.
+ * gcc.dg/pr35691-2.c: Likewise.
+ * gcc.dg/pr35691-3.c: New test.
+ * gcc.dg/pr35691-4.c: New test.
+
PR sanitizer/81929
* g++.dg/ubsan/pr81929.C: New test.
diff --git a/gcc/testsuite/gcc.dg/pr35691-1.c b/gcc/testsuite/gcc.dg/pr35691-1.c
index 125923d..34dc02a 100644
--- a/gcc/testsuite/gcc.dg/pr35691-1.c
+++ b/gcc/testsuite/gcc.dg/pr35691-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop-details" } */
+/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
int foo(int z0, unsigned z1)
{
diff --git a/gcc/testsuite/gcc.dg/pr35691-2.c b/gcc/testsuite/gcc.dg/pr35691-2.c
index 70f68a6..b89ce48 100644
--- a/gcc/testsuite/gcc.dg/pr35691-2.c
+++ b/gcc/testsuite/gcc.dg/pr35691-2.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop-details" } */
+/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
int foo(int z0, unsigned z1)
{
diff --git a/gcc/testsuite/gcc.dg/pr35691-3.c b/gcc/testsuite/gcc.dg/pr35691-3.c
new file mode 100644
index 0000000..75b49a6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr35691-3.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+
+int foo(int z0, unsigned z1)
+{
+ int t0 = (z0 == -1);
+ int t1 = (z1 == -1U);
+ int t2 = (t0 & t1);
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/pr35691-4.c b/gcc/testsuite/gcc.dg/pr35691-4.c
new file mode 100644
index 0000000..2d9456b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr35691-4.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+
+int foo(int z0, unsigned z1)
+{
+ int t0 = (z0 != -1);
+ int t1 = (z1 != -1U);
+ int t2 = (t0 | t1);
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */