tree-optimization/113707 - ICE with VN elimination

The following avoids different avail answers depending on how the
iteration progressed.

	PR tree-optimization/113707
	* tree-ssa-sccvn.cc (rpo_elim::eliminate_avail): After
	checking the avail set treat out-of-region defines as
	available.

	* gcc.dg/torture/pr113707-1.c: New testcase.
	* gcc.dg/torture/pr113707-2.c: Likewise.
This commit is contained in:
Richard Biener 2024-02-05 09:44:12 +01:00
parent 9d139c0365
commit 42959acb84
3 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,45 @@
/* { dg-do compile } */
int printf(const char *, ...);
struct a {
int b;
} n;
int a, c, d, e, f = 1, g, h, j = 1, k, l, m, o;
int main() {
struct a p;
int i;
p.b = 1;
if (!j)
goto q;
p.b = i = 0;
for (; i < 1; i++)
if (k)
while (m)
r:
q:
if (p.b)
g = 1;
while (1) {
i = 0;
for (; i < 5; i++)
;
if (l) {
while (h)
;
if (o) {
d = 0;
for (; d < 8; d++)
;
}
}
for (; e; e--)
while (a)
p = n;
if (c)
goto r;
printf("0");
if (f)
break;
}
return 0;
}

View file

@ -0,0 +1,26 @@
/* { dg-do compile } */
int a, b, c, d, e, f, g, h, j, k, l;
void n() {
while (c)
if (1) {
for (h = 5; h; h--) {
int m = e % 2;
d = ~g || h ^ m / -1;
if (h > 5)
e = k;
}
return;
}
}
int main() {
if (a)
for (int i = 0; i < 2; i++) {
for (f = 1; f < 6; f++)
for (c = 7; c >= 0; c--)
if (l)
b = 0;
n();
}
return 0;
}

View file

@ -7776,6 +7776,11 @@ rpo_elim::eliminate_avail (basic_block bb, tree op)
av = av->next;
}
while (av);
/* While we prefer avail we have to fallback to using the value
directly if defined outside of the region when none of the
available defs suit. */
if (!valnum_info->visited)
return valnum;
}
else if (valnum != VN_TOP)
/* valnum is is_gimple_min_invariant. */