public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] Fix PR78546
@ 2016-11-28 16:23 Bernd Edlinger
  0 siblings, 0 replies; 3+ messages in thread
From: Bernd Edlinger @ 2016-11-28 16:23 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi Richard,


I am just wondering if this might be a mistake,
because this looks somehow odd:

 > +  /* CST - (CST - A) -> CST - A  */
 > +  (simplify
 > +   (minus CONSTANT_CLASS_P@1 (minus CONSTANT_CLASS_P@2 @0))
 > +   (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); }
 > +    (if (cst && !TREE_OVERFLOW (cst))
 > +     (minus { cst; } @0))))


isn't CST1 - (CST2 - A) == (CST1 - CST2) + A
thus (plus { cst; } @0) ??


Bernd.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR78546
  2016-11-28 12:42 Richard Biener
@ 2016-11-29  7:50 ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2016-11-29  7:50 UTC (permalink / raw)
  To: gcc-patches

On Mon, 28 Nov 2016, Richard Biener wrote:

> 
> The following fixes an optimization regression noted in PR78546 where
> moving patterns from forwprop to match.pd missed one variant.
> 
> Bootstrap & regtest running on x86_64-unknown-linux-gnu.

The following is what I have applied (note the fix, the transform
obviously need to transform to CST + A).  I've adjusted surrounding
patterns to use different CST names in comments.

Richard.

2016-11-29  Richard Biener  <rguenther@suse.de>

	PR middle-end/78546
	* match.pd: Add CST1 - (CST2 - A) -> CST3 + A missing case.

	* gcc.dg/tree-ssa/forwprop-36.c: New testcase.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 242952)
+++ gcc/match.pd	(working copy)
@@ -1195,7 +1195,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (minus @0 (minus @0 @1))
    @1)
 
-  /* (A +- CST) +- CST -> A + CST  */
+  /* (A +- CST1) +- CST2 -> A + CST3  */
   (for outer_op (plus minus)
    (for inner_op (plus minus)
     (simplify
@@ -1208,7 +1208,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       (if (cst && !TREE_OVERFLOW (cst))
        (inner_op @0 { cst; } ))))))
 
-  /* (CST - A) +- CST -> CST - A  */
+  /* (CST1 - A) +- CST2 -> CST3 - A  */
   (for outer_op (plus minus)
    (simplify
     (outer_op (minus CONSTANT_CLASS_P@1 @0) CONSTANT_CLASS_P@2)
@@ -1216,6 +1216,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      (if (cst && !TREE_OVERFLOW (cst))
       (minus { cst; } @0)))))
 
+  /* CST1 - (CST2 - A) -> CST3 + A  */
+  (simplify
+   (minus CONSTANT_CLASS_P@1 (minus CONSTANT_CLASS_P@2 @0))
+   (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); }
+    (if (cst && !TREE_OVERFLOW (cst))
+     (plus { cst; } @0))))
+
   /* ~A + A -> -1 */
   (simplify
    (plus:c (bit_not @0) @0)
Index: gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c	(working copy)
@@ -0,0 +1,24 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+typedef unsigned __int128 u128;
+
+u128 a, b;
+
+static inline u128
+foo (u128 p1)
+{
+  p1 += ~b;
+  return -p1;
+}
+
+int
+main ()
+{
+  u128 x = foo (~0x7fffffffffffffff);
+  if (x != 0x8000000000000001)
+    __builtin_abort();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "if \\(b.0_\[0-9\]+ != 0\\)" "cddce1" } } */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Fix PR78546
@ 2016-11-28 12:42 Richard Biener
  2016-11-29  7:50 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2016-11-28 12:42 UTC (permalink / raw)
  To: gcc-patches


The following fixes an optimization regression noted in PR78546 where
moving patterns from forwprop to match.pd missed one variant.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2016-11-28  Richard Biener  <rguenther@suse.de>

	PR middle-end/78546
	* match.pd: Add CST - (CST - A) -> CST - A missing case.

	* gcc.dg/tree-ssa/forwprop-36.c: New testcase.

diff --git a/gcc/match.pd b/gcc/match.pd
index 2d4e019..9e5df64 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1216,6 +1216,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      (if (cst && !TREE_OVERFLOW (cst))
       (minus { cst; } @0)))))
 
+  /* CST - (CST - A) -> CST - A  */
+  (simplify
+   (minus CONSTANT_CLASS_P@1 (minus CONSTANT_CLASS_P@2 @0))
+   (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); }
+    (if (cst && !TREE_OVERFLOW (cst))
+     (minus { cst; } @0))))
+
   /* ~A + A -> -1 */
   (simplify
    (plus:c (bit_not @0) @0)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
new file mode 100644
index 0000000..9de73ff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
@@ -0,0 +1,24 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+typedef unsigned __int128 u128;
+
+u128 a, b;
+
+static inline u128
+foo (u128 p1)
+{
+  p1 += ~b;
+  return -p1;
+}
+
+int
+main ()
+{
+  u128 x = foo (~0x7fffffffffffffff);
+  if (x != 0x8000000000000001)
+    __builtin_abort();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "if \\(b.0_\[0-9\]+ != 0\\)" "cddce1" } } */

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-29  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28 16:23 [PATCH] Fix PR78546 Bernd Edlinger
  -- strict thread matches above, loose matches on Subject: below --
2016-11-28 12:42 Richard Biener
2016-11-29  7:50 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).