public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1134] Range invariant global values are also always current.
@ 2021-06-01  1:31 Andrew Macleod
  0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2021-06-01  1:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1ffbfc2659e7e8fa5c5d633869870af8fca5e8ee

commit r12-1134-g1ffbfc2659e7e8fa5c5d633869870af8fca5e8ee
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Thu May 27 11:19:10 2021 -0400

    Range invariant global values are also always current.
    
    when a range evolves to the point where it becomes a constant, it is
    marked as invariant.  Rather than marking it as always_current in the
    timestamp, give it the correct timestamp and just never flag it as stale.
    This will allow other names which use this value to become stale and be
    recomputed using the newly invariant value.
    
            gcc/
            PR tree-optimization/100774
            * gimple-range-cache.cc (ranger_cache::get_non_stale_global_range):
            Constant values are also not stale.
            (ranger_cache::set_global_range): Range invariant values should also
            have the correct timestamp.
    
            gcc/testsuite
            PR tree-optimization/100774
            * g++.dg/pr100774.C: New.

Diff:
---
 gcc/gimple-range-cache.cc       | 16 ++++++++--------
 gcc/testsuite/g++.dg/pr100774.C | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 889cac1ea65..ef3bc044891 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -639,7 +639,9 @@ ranger_cache::get_non_stale_global_range (irange &r, tree name)
 {
   if (m_globals.get_global_range (r, name))
     {
-      if (m_temporal->current_p (name, depend1 (name), depend2 (name)))
+      // Use this value if the range is constant or current.
+      if (r.singleton_p ()
+	  || m_temporal->current_p (name, depend1 (name), depend2 (name)))
 	return true;
     }
   else
@@ -674,15 +676,13 @@ ranger_cache::set_global_range (tree name, const irange &r)
   // undefined. Propagation works better with constants. PR 100512.
   // Pointers which resolve to non-zero also do not need
   // tracking in the cache as they will never change.  See PR 98866.
-  // Otherwise mark the value as up-to-date.
+  // Timestamp must always be updated, or dependent calculations may
+  // not include this latest value. PR 100774.
+
   if (r.singleton_p ()
       || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ()))
-    {
-      set_range_invariant (name);
-      m_temporal->set_always_current (name);
-    }
-  else
-    m_temporal->set_timestamp (name);
+    set_range_invariant (name);
+  m_temporal->set_timestamp (name);
 }
 
 // Push a request for a new lookup in block BB of name.  Return true if
diff --git a/gcc/testsuite/g++.dg/pr100774.C b/gcc/testsuite/g++.dg/pr100774.C
new file mode 100644
index 00000000000..345fcfa0d01
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr100774.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --param=evrp-mode=ranger -fcompare-debug  " } */
+
+extern void __attribute__((noreturn)) error();
+
+int x;
+
+static inline int bar(void) {
+  char n = 1;
+  int i = x & 1U << n - 1;
+  return i;
+}
+
+void foo()
+{
+  int a = bar();
+  for (;;) {
+    bool b;
+    int d = a;
+    b = a < 2;
+    if (!b)
+      error();
+  }
+}


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

only message in thread, other threads:[~2021-06-01  1:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01  1:31 [gcc r12-1134] Range invariant global values are also always current Andrew Macleod

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).