public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-852] Once a range becomes constant, make it invariant.
@ 2021-05-17 22:13 Andrew Macleod
  0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2021-05-17 22:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3f476de7fd274f619a0b04c2e2f7077ee8ab17a5

commit r12-852-g3f476de7fd274f619a0b04c2e2f7077ee8ab17a5
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon May 17 15:53:39 2021 -0400

    Once a range becomes constant, make it invariant.
    
    Once a range is forced to a constant globally, simply make it invariant.
    Unify this with the code which makes non-zero pointer ranges invariant.
    
            gcc/
            PR tree-optimization/100512
            * gimple-range-cache.cc (ranger_cache::set_global_range): Mark const
            and non-zero pointer ranges as invariant.
            * gimple-range.cc (gimple_ranger::range_of_stmt): Remove pointer
            processing from here.
    
            gcc/testsuite/
            PR tree-optimization/100512
            * gcc.dg/pr100512.c: New.

Diff:
---
 gcc/gimple-range-cache.cc       | 15 +++++++++++++--
 gcc/gimple-range.cc             |  5 -----
 gcc/testsuite/gcc.dg/pr100512.c | 25 +++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 60e5d66c52d..2c922e32913 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -703,8 +703,19 @@ ranger_cache::set_global_range (tree name, const irange &r)
 
       propagate_updated_value (name, bb);
     }
-  // Mark the value as up-to-date.
-  m_temporal->set_timestamp (name);
+  // Constants no longer need to tracked.  Any further refinement has to be
+  // 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.
+  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);
 }
 
 // Register a dependency on DEP to name.  If the timestamp for DEP is ever
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 5b288d8e6a7..710bc7f9632 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -1082,11 +1082,6 @@ gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name)
   r.intersect (tmp);
   m_cache.set_global_range (name, r);
 
-  // Pointers which resolve to non-zero at the defintion point do not need
-  // tracking in the cache as they will never change.  See PR 98866.
-  if (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())
-    m_cache.set_range_invariant (name);
-
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr100512.c b/gcc/testsuite/gcc.dg/pr100512.c
new file mode 100644
index 00000000000..70b90e04be9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100512.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -w" } */
+
+#include <stdint.h>
+int a;
+void b() {
+  int16_t *c;
+  uint16_t d = 2;
+  if (0 == d) {
+    uint64_t e;
+    uint64_t *f = &e;
+    for (;;) {
+      if (e += 0 >= 0)
+        for (;;)
+          ;
+    g:
+      for (; a;) {
+        int16_t i = &d;
+        *c = i && *f;
+      }
+    }
+  }
+  goto g;
+}
+


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

only message in thread, other threads:[~2021-05-17 22:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 22:13 [gcc r12-852] Once a range becomes constant, make it invariant 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).