From: Richard Biener Date: Tue, 25 Aug 2020 08:59:24 +0000 (+0200) Subject: tree-optimization/96548 - fix failure to recompute RPO after CFG change X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=660b5c10dc04988b02a2c3f6baed013340af3ef8;p=gcc.git 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 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. --- diff --git a/gcc/testsuite/gcc.dg/torture/pr96548.c b/gcc/testsuite/gcc.dg/torture/pr96548.c new file mode 100644 index 00000000000..a0547427d29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr96548.c @@ -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; + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr96760.c b/gcc/testsuite/gcc.dg/torture/pr96760.c new file mode 100644 index 00000000000..4f6bbe96faf --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr96760.c @@ -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; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 35da1fb26a6..f87c287d742 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -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]));