On September 22, 2017 6:59:48 PM GMT+02:00, Jakub Jelinek <ja...@redhat.com> 
wrote:
>Hi!
>
>While fixing libgcc2.c (__mulvDI3), I've noticed that while we
>optimize x == 0 && y == 0 into (x | y) == 0, we don't optimize
>analogical x == -1 && y == -1 into (x & y) == -1.
>
>The following patch does that, bootstrapped/regtested on x86_64-linux
>and
>i686-linux, ok for trunk?

OK. 

Thanks, 
Richard. 

>2017-09-22  Jakub Jelinek  <ja...@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.
>
>       * 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.
>
>--- gcc/match.pd.jj    2017-09-15 20:42:29.000000000 +0200
>+++ gcc/match.pd       2017-09-22 13:34:29.413534762 +0200
>@@ -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
>--- gcc/testsuite/gcc.dg/pr35691-1.c.jj        2016-11-09 15:22:31.000000000
>+0100
>+++ gcc/testsuite/gcc.dg/pr35691-1.c   2017-09-22 13:58:32.665455251
>+0200
>@@ -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)
> {
>--- gcc/testsuite/gcc.dg/pr35691-2.c.jj        2016-11-09 15:22:32.000000000
>+0100
>+++ gcc/testsuite/gcc.dg/pr35691-2.c   2017-09-22 13:58:38.174386317
>+0200
>@@ -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)
> {
>--- gcc/testsuite/gcc.dg/pr35691-3.c.jj        2017-09-22 13:55:36.186663576
>+0200
>+++ gcc/testsuite/gcc.dg/pr35691-3.c   2017-09-22 13:58:44.070312539
>+0200
>@@ -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" } } */
>--- gcc/testsuite/gcc.dg/pr35691-4.c.jj        2017-09-22 13:55:39.855617665
>+0200
>+++ gcc/testsuite/gcc.dg/pr35691-4.c   2017-09-22 13:58:50.132236685
>+0200
>@@ -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" } } */
>
>       Jakub

Reply via email to