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