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 r12-8246] Retain existing range knowledge when prefilling statements.
Date: Mon, 25 Apr 2022 13:59:24 +0000 (GMT)	[thread overview]
Message-ID: <20220425135924.2F3AC3858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:362e2a9c6297203bcf7f66bfb51dffb82b42d3b3

commit r12-8246-g362e2a9c6297203bcf7f66bfb51dffb82b42d3b3
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Apr 25 09:56:35 2022 -0400

    Retain existing range knowledge when prefilling statements.
    
    When range_of_stmt was adjusted to avoid large recursion depth, we need to
    intersect the calculated range whth the any known range to avoid losing
    info.  Range_of_stmt does this, but the new prefill code missed it.
    
            PR tree-optimization/105276
            gcc/
            * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Include
            existing global range with calculated value.
    
            gcc/testsuite/
            * g++.dg/pr105276.C: New.

Diff:
---
 gcc/gimple-range.cc             |  4 ++++
 gcc/testsuite/g++.dg/pr105276.C | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 04075a98a80..f0caefce2a3 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -394,6 +394,10 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa)
 	      // Fold and save the value for NAME.
 	      stmt = SSA_NAME_DEF_STMT (name);
 	      fold_range_internal (r, stmt, name);
+	      // Make sure we don't lose any current global info.
+	      int_range_max tmp;
+	      m_cache.get_global_range (tmp, name);
+	      r.intersect (tmp);
 	      m_cache.set_global_range (name, r);
 	    }
 	  continue;
diff --git a/gcc/testsuite/g++.dg/pr105276.C b/gcc/testsuite/g++.dg/pr105276.C
new file mode 100644
index 00000000000..ad0e9dd7e09
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr105276.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+bool
+foo(unsigned i)
+{
+  bool result = true;
+  while (i)
+    {
+      i = i % 3;
+      i = i - (i == 2 ? 2 : i ? 1 : 0);
+      result = !result;
+    }
+  return result;
+}
+
+/* We should be able to eliminate the i - operation.  */
+/* { dg-final { scan-tree-dump-not "i_.* - " "optimized" } } */


                 reply	other threads:[~2022-04-25 13:59 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=20220425135924.2F3AC3858D28@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).