The following avoids corrupting the SCEV cache by my last change
to propagate constant final values immediately. The easiest fix
is to keep a dead initialization around.
PR tree-optimization/112827
* tree-scalar-evolution.cc (final_value_replacement_loop):
Do not release SSA name but keep a dead initialization around.
* gcc.dg/torture/pr112827-1.c: New testcase.
* gcc.dg/torture/pr112827-2.c: Likewise.
--- /dev/null
+/* { dg-do compile } */
+
+int a, b, c, d, e;
+int main() {
+ for (; c; c++) {
+ for (a = 0; a < 2; a++)
+ ;
+ for (; b; b++) {
+ e = d;
+ d = a;
+ }
+ }
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+
+short a, b[1], f;
+char c, g;
+int d, e;
+int main() {
+ for (; f; f++) {
+ for (d = 0; d < 2; d++)
+ ;
+ if (a)
+ for (g = 0; g < 2; g++)
+ for (c = 0; c < 2; c += b[d+g])
+ ;
+ for (; e; e++)
+ ;
+ }
+ return 0;
+}
def = unshare_expr (def);
remove_phi_node (&psi, false);
- /* Propagate constants immediately. */
+ /* Propagate constants immediately, but leave an unused initialization
+ around to avoid invalidating the SCEV cache. */
if (CONSTANT_CLASS_P (def))
- {
- replace_uses_by (rslt, def);
- release_ssa_name (rslt);
- continue;
- }
+ replace_uses_by (rslt, def);
/* Create the replacement statements. */
gimple_seq stmts;