public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5872] tree-optimization/112706 - missed simplification of condition
@ 2023-11-27  9:43 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-27  9:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d9abaa8d58f5729925b1db735d4723a9ea825eaa

commit r14-5872-gd9abaa8d58f5729925b1db735d4723a9ea825eaa
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Nov 27 09:45:04 2023 +0100

    tree-optimization/112706 - missed simplification of condition
    
    We lack a match.pd pattern recognizing ptr + o ==/!= ptr + o'.
    The following extends handling we have for integral types to
    pointers.
    
            PR tree-optimization/112706
            * match.pd (ptr + o ==/!=/- ptr + o'): New patterns.
    
            * gcc.dg/tree-ssa/pr112706.c: New testcase.

Diff:
---
 gcc/match.pd                             |  9 +++++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr112706.c | 15 +++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 61e5d3441f4..95225e4ca5f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2596,6 +2596,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
 	   || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))))
    (op @0 @1))))
+/* And similar for pointers.  */
+(for op (eq ne)
+ (simplify
+  (op (pointer_plus @0 @1) (pointer_plus @0 @2))
+  (op @1 @2)))
+(simplify
+ (pointer_diff (pointer_plus @0 @1) (pointer_plus @0 @2))
+ (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
+  (convert (minus @1 @2))))
 
 /* X - Z < Y - Z is the same as X < Y when there is no overflow.  */
 (for op (lt le ge gt)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr112706.c b/gcc/testsuite/gcc.dg/tree-ssa/pr112706.c
new file mode 100644
index 00000000000..217730b99b2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr112706.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1" } */
+
+int *ptr;
+void link_error ();
+void
+test ()
+{
+  int *ptr1 = ptr + 10;
+  int *ptr2 = ptr + 20;
+  if (ptr1 == ptr2)
+    link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "if" "fre1" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-27  9:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27  9:43 [gcc r14-5872] tree-optimization/112706 - missed simplification of condition 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).