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.
--- /dev/null
+/* { 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;
+ }
+}
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;