Reset SCEV before removing unreachable globals.

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.
This commit is contained in:
Andrew MacLeod 2023-02-01 11:46:18 -05:00
parent 27ac6a707e
commit 093e2e1b20
2 changed files with 29 additions and 0 deletions

View file

@ -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;
}
}

View 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;