public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1356] Don't use gori dependencies to optimize.
Date: Thu, 30 Jun 2022 01:39:45 +0000 (GMT)	[thread overview]
Message-ID: <20220630013945.028553846456@sourceware.org> (raw)

https://gcc.gnu.org/g:918ccccbb0e78ae42bfcf808a1e93a8f6b9d02ea

commit r13-1356-g918ccccbb0e78ae42bfcf808a1e93a8f6b9d02ea
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Jun 29 13:34:05 2022 -0400

    Don't use gori dependencies to optimize.
    
      The routine fold_using_range::relation_fold_and_or needs to veriyf that both
    operands of 2 stmts are the same, and uses GORIs dependency cache for this.
    This cache cannot be counted on to reflect the current contents of a
    stmt, expecially in the presence of an IL changing pass.  Instead, look at the
    statement operands.
    
            PR tree-optimization/106114
            gcc/
            * gimple-range-fold.cc (fold_using_range::relation_fold_and_or): Check
            statement operands instead of GORI cache.
            gcc/testsuite/
            * gcc.dg/pr106114.c: New.

Diff:
---
 gcc/gimple-range-fold.cc        | 30 +++++++++++++++++-------------
 gcc/testsuite/gcc.dg/pr106114.c | 14 ++++++++++++++
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 2a8c66e0c05..0f815b50b9a 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -1397,14 +1397,25 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s,
   // Ideally we search dependencies for common names, and see what pops out.
   // until then, simply try to resolve direct dependencies.
 
-  // Both names will need to have 2 direct dependencies.
-  tree ssa1_dep2 = src.gori ()->depend2 (ssa1);
-  tree ssa2_dep2 = src.gori ()->depend2 (ssa2);
-  if (!ssa1_dep2 || !ssa2_dep2)
+  gimple *ssa1_stmt = SSA_NAME_DEF_STMT (ssa1);
+  gimple *ssa2_stmt = SSA_NAME_DEF_STMT (ssa2);
+
+  range_op_handler handler1 (SSA_NAME_DEF_STMT (ssa1));
+  range_op_handler handler2 (SSA_NAME_DEF_STMT (ssa2));
+
+  // If either handler is not present, no relation can be found.
+  if (!handler1 || !handler2)
+    return;
+
+  // Both stmts will need to have 2 ssa names in the stmt.
+  tree ssa1_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa1_stmt));
+  tree ssa1_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa1_stmt));
+  tree ssa2_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa2_stmt));
+  tree ssa2_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa2_stmt));
+
+  if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2)
     return;
 
-  tree ssa1_dep1 = src.gori ()->depend1 (ssa1);
-  tree ssa2_dep1 = src.gori ()->depend1 (ssa2);
   // Make sure they are the same dependencies, and detect the order of the
   // relationship.
   bool reverse_op2 = true;
@@ -1413,13 +1424,6 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s,
   else if (ssa1_dep1 != ssa2_dep2 || ssa1_dep2 != ssa2_dep1)
     return;
 
-  range_op_handler handler1 (SSA_NAME_DEF_STMT (ssa1));
-  range_op_handler handler2 (SSA_NAME_DEF_STMT (ssa2));
-
-  // If either handler is not present, no relation is found.
-  if (!handler1 || !handler2)
-    return;
-
   int_range<2> bool_one (boolean_true_node, boolean_true_node);
 
   relation_kind relation1 = handler1.op1_op2_relation (bool_one);
diff --git a/gcc/testsuite/gcc.dg/pr106114.c b/gcc/testsuite/gcc.dg/pr106114.c
new file mode 100644
index 00000000000..64c8b8d390a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106114.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dom2" } */
+
+int printf(const char *, ...);
+char a = 139, b;
+int main() {
+  char c = 173;
+  b = a;
+  while (c <= a || a < -117)
+    c = printf("0\n");
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times  "if" 2 "dom2" } }  */


                 reply	other threads:[~2022-06-30  1:39 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=20220630013945.028553846456@sourceware.org \
    --to=amacleod@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).