diff mbox series

[COMMITTED] PR tree-optimization/110875 - Some ssa-names get incorrectly marked as always_current.

Message ID 6130f27c-ca74-1d41-6edb-bc6b7cb88890@redhat.com
State New
Headers show
Series [COMMITTED] PR tree-optimization/110875 - Some ssa-names get incorrectly marked as always_current. | expand

Commit Message

Andrew MacLeod Sept. 7, 2023, 7:21 p.m. UTC
When range_of_stmt invokes prefill_name to evaluate unvisited 
dependneciesit should not mark visited names as always_current.

when raner_cache::get_globaL_range() is invoked with the optional  
"current_p" flag, it triggers additional functionality. This call is 
meant to be from within ranger and it is understood that if the current 
value is not current,  set_global_range will always be called later with 
a value.  Thus it sets the always_current flag in the temporal cache to 
avoid computation cycles.

the prefill_stmt_dependencies () mechanism within ranger is intended to 
emulate the bahaviour od range_of_stmt on an arbitrarily long series of 
unresolved dependencies without triggering the overhead of huge call 
chains from the range_of_expr/range_on_entry/range_on_exit routines.  
Rather, it creates a stack of unvisited names, and invokes range_of_stmt 
on them directly in order to get initial cache values for each ssa-name.

The issue in this PR was that routine was incorrectly invoking the 
get_global_cache to determine whether there was a global value.  If 
there was, it would move on to the next dependency without invoking 
set_global_range to clear the always_current flag.

What it soudl have been doing was simply checking if there as a global 
value, and if there was not, add the name for processingand THEN invoke 
get_global_value to do all the special processing.

Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
diff mbox series

Patch

From e9be59f7d2dc6b302cf85ad69b0a77dee89ec809 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Thu, 7 Sep 2023 11:15:50 -0400
Subject: [PATCH] Some ssa-names get incorrectly marked as always_current.

When range_of_stmt invokes prefill_name to evaluate unvisited dependencies
it should not mark already visited names as always_current.

	PR tree-optimization/110875
	gcc/
	* gimple-range.cc (gimple_ranger::prefill_name): Only invoke
	cache-prefilling routine when the ssa-name has no global value.

	gcc/testsuite/
	* gcc.dg/pr110875.c: New.
---
 gcc/gimple-range.cc             | 10 +++++++---
 gcc/testsuite/gcc.dg/pr110875.c | 34 +++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr110875.c

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 01173c58f02..13c3308d537 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -351,10 +351,14 @@  gimple_ranger::prefill_name (vrange &r, tree name)
   if (!gimple_range_op_handler::supported_p (stmt) && !is_a<gphi *> (stmt))
     return;
 
-  bool current;
   // If this op has not been processed yet, then push it on the stack
-  if (!m_cache.get_global_range (r, name, current))
-    m_stmt_list.safe_push (name);
+  if (!m_cache.get_global_range (r, name))
+    {
+      bool current;
+      // Set the global cache value and mark as alway_current.
+      m_cache.get_global_range (r, name, current);
+      m_stmt_list.safe_push (name);
+    }
 }
 
 // This routine will seed the global cache with most of the dependencies of
diff --git a/gcc/testsuite/gcc.dg/pr110875.c b/gcc/testsuite/gcc.dg/pr110875.c
new file mode 100644
index 00000000000..4d6ecbca0c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr110875.c
@@ -0,0 +1,34 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp2" } */
+
+void foo(void);
+static int a, b;
+static int *c = &a, *d;
+static unsigned e;
+static short f;
+static unsigned g(unsigned char h, char i) { return h + i; }
+int main() {
+    d = &a;
+    int *j = d;
+    e = -27;
+    for (; e > 18; e = g(e, 6)) {
+        a = 0;
+        for (; a != -3; a--) {
+            if (0 != a ^ *j)
+                for (; b; b++) f = -f;
+            else if (*c) {
+                foo();
+                break;
+            }
+            if (!(((e) >= 235) && ((e) <= 4294967269))) {
+                __builtin_unreachable();
+            }
+            b = 0;
+        }
+    }
+}
+
+
+/* { dg-final { scan-tree-dump-not "foo" "vrp2" } } */
+
+
-- 
2.41.0