tree-optimization/96548 - fix failure to recompute RPO after CFG change

This recomputes RPO after store-motion changes the CFG.

2020-08-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/96548
	PR tree-optimization/96760
	* tree-ssa-loop-im.c (tree_ssa_lim): Recompute RPO after
	store-motion.

	* gcc.dg/torture/pr96548.c: New testcase.
	* gcc.dg/torture/pr96760.c: Likewise.
This commit is contained in:
Richard Biener 2020-08-25 10:59:24 +02:00
parent a5b15fcb95
commit 660b5c10dc
3 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,20 @@
/* { dg-do compile } */
int c9, d3;
void
sg (int *rs, int f2)
{
for (;;)
{
if (*rs < 1)
__builtin_unreachable ();
for (c9 = 0; c9 < 1; ++c9)
while (f2 < 1)
++c9;
if (d3)
c9 += !!f2 ? 0 : d3;
}
}

View file

@ -0,0 +1,22 @@
/* { dg-do run } */
char a = 0, f = 0, c = 5;
unsigned long d = 0;
int g = 0;
int *e = &g;
int main() {
char b = 0;
for (;;) {
for (a = 0; a < 2; a++) { // no UB I believe
if (c) {
if (d != 0)
__builtin_abort ();
return 0;
}
}
f = (d++, *e);
}
return 1;
}

View file

@ -3115,6 +3115,10 @@ tree_ssa_lim (function *fun)
out of the loops as well. */
do_store_motion ();
free (rpo);
rpo = XNEWVEC (int, last_basic_block_for_fn (fun));
n = pre_and_rev_post_order_compute_fn (fun, NULL, rpo, false);
/* Move the expressions that are expensive enough. */
for (int i = 0; i < n; ++i)
todo |= move_computations_worker (BASIC_BLOCK_FOR_FN (fun, rpo[i]));