Reset SCEV before removing unreachable globals.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 1 Feb 2023 16:46:18 +0000 (11:46 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Fri, 3 Feb 2023 19:42:46 +0000 (14:42 -0500)
SCEV should be reset in VRP before trying to remove unreachable globals
to avoid triggering issues with it's cache.

PR tree-optimization/107570
gcc/
* tree-vrp.cc (remove_and_update_globals): Reset SCEV.

gcc/testsuite/
* gcc.dg/pr107570.c: New.

gcc/testsuite/gcc.dg/pr107570.c [new file with mode: 0644]
gcc/tree-vrp.cc

diff --git a/gcc/testsuite/gcc.dg/pr107570.c b/gcc/testsuite/gcc.dg/pr107570.c
new file mode 100644 (file)
index 0000000..ba5b535
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+long int n;
+
+void
+foo (int *p, int x)
+{
+  for (;;)
+    {
+      for (*p = 0; *p < 1; ++*p)
+        {
+          n += *p < 0;
+          if (n < x)
+            {
+              while (x < 1)
+                ++x;
+
+              __builtin_unreachable ();
+            }
+        }
+
+      p = &x;
+    }
+}
index 3c43176..95547e5 100644 (file)
@@ -121,6 +121,10 @@ remove_unreachable::remove_and_update_globals (bool final_p)
   if (m_list.length () == 0)
     return false;
 
+  // Ensure the cache in SCEV has been cleared before processing
+  // globals to be removed.
+  scev_reset ();
+
   bool change = false;
   tree name;
   unsigned i;