The following makes sure SSA operands are up-to-date before folding.
Esp. when replace_uses_by is invoked from SCEV cprop which now has
ranger enabled we can otherwise end up ICEing where purpoted SSA
names now are constants. This follows what forwprop does.
PR tree-optimization/124692
* tree-cfg.cc (replace_uses_by): Call update_stmt after
substitution and before folding.
* gcc.dg/torture/pr124692.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+
+int a, b, d, e[3][1], f, g, h;
+unsigned c;
+int main()
+{
+ while (b)
+ {
+ h = g;
+ for (b = 0; b < 2; b++)
+ ;
+ for (; c; c++)
+ {
+ int j = e[b][h];
+ f = a < 0 ? j : j - a;
+ if (!f)
+ break;
+ g = c;
+ }
+ }
+ return 0;
+}
if (op && TREE_CODE (op) == ADDR_EXPR)
recompute_tree_invariant_for_addr_expr (op);
}
+ update_stmt (stmt);
if (fold_stmt (&gsi))
- stmt = gsi_stmt (gsi);
+ {
+ stmt = gsi_stmt (gsi);
+ update_stmt (stmt);
+ }
if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
gimple_purge_dead_eh_edges (gimple_bb (stmt));
-
- update_stmt (stmt);
}
}