public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4607] tree-optimization/89317 - another pattern for &p->x != p + 4
Date: Mon, 12 Dec 2022 07:55:22 +0000 (GMT)	[thread overview]
Message-ID: <20221212075522.84A8B39577AD@sourceware.org> (raw)

https://gcc.gnu.org/g:2dc5d6b1e7ec8822f5bd78761962ca2c85d4a2b4

commit r13-4607-g2dc5d6b1e7ec8822f5bd78761962ca2c85d4a2b4
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 12 08:13:33 2022 +0100

    tree-optimization/89317 - another pattern for &p->x != p + 4
    
    As seen in the original testcase for PR89317 we are missing
    comparison simplification patterns for &p->x != p + 4.  Fixed
    by making an existing one apply.  To make the pattern apply
    during CCP we need to simplify ccp_fold to not use GENERIC
    folding of conditions but also use GIMPLE folding.
    
            PR tree-optimization/89317
            * tree-ssa-ccp.cc (ccp_fold): Handle GIMPLE_COND via
            gimple_fold_stmt_to_constant_1.
            * match.pd (&a != &a + c): Apply to pointer_plus with non-ADDR_EXPR
            base as well.
    
            * gcc.dg/tree-ssa/pr89317.c: Amend.

Diff:
---
 gcc/match.pd                            |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr89317.c | 17 +++++++++++++++++
 gcc/tree-ssa-ccp.cc                     | 11 +----------
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index ba83c69734f..3517605c04d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2263,7 +2263,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* (&a + b) !=/== (&a[1] + c) -> (&a[0] - &a[1]) + b !=/== c */
 (for neeq (ne eq)
  (simplify
-  (neeq:c ADDR_EXPR@0 (pointer_plus ADDR_EXPR@2 @3))
+  (neeq:c ADDR_EXPR@0 (pointer_plus @2 @3))
    (with { poly_int64 diff; tree inner_type = TREE_TYPE (@3);}
     (if (ptr_difference_const (@0, @2, &diff))
      (neeq { build_int_cst_type (inner_type, diff); } @3))))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89317.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89317.c
index 0d0a049454f..0c8f2f53a45 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr89317.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr89317.c
@@ -10,4 +10,21 @@ int foo (struct b *x)
   return b - a;
 }
 
+int bar (struct b *x)
+{
+  int *a = x->data;
+  int *b = ((int*)x) + 4;
+  if (a != b)
+    return 1;
+  return 0;
+}
+
+int baz (struct b *x)
+{
+  int *a = x->data;
+  int *b = ((int*)x) + 4;
+  return (a != b);
+}
+
 /* { dg-final { scan-tree-dump "return 4;" "ccp1" } } */
+/* { dg-final { scan-tree-dump-times "return 1;" 2 "ccp1" } } */
diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index 69fd7f1d11d..68e69bfe129 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -1271,24 +1271,15 @@ valueize_op_1 (tree op)
 static tree
 ccp_fold (gimple *stmt)
 {
-  location_t loc = gimple_location (stmt);
   switch (gimple_code (stmt))
     {
-    case GIMPLE_COND:
-      {
-        /* Handle comparison operators that can appear in GIMPLE form.  */
-        tree op0 = valueize_op (gimple_cond_lhs (stmt));
-        tree op1 = valueize_op (gimple_cond_rhs (stmt));
-        enum tree_code code = gimple_cond_code (stmt);
-        return fold_binary_loc (loc, code, boolean_type_node, op0, op1);
-      }
-
     case GIMPLE_SWITCH:
       {
 	/* Return the constant switch index.  */
         return valueize_op (gimple_switch_index (as_a <gswitch *> (stmt)));
       }
 
+    case GIMPLE_COND:
     case GIMPLE_ASSIGN:
     case GIMPLE_CALL:
       return gimple_fold_stmt_to_constant_1 (stmt,

                 reply	other threads:[~2022-12-12  7:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221212075522.84A8B39577AD@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).