diff options
author | Richard Biener <rguenther@suse.de> | 2023-12-04 10:46:11 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-12-04 12:53:55 +0100 |
commit | de0ab339a795352c843f6e9b2dfce222f26588de (patch) | |
tree | 9ef451aa44f70cf0b093a79961dcdb7ddd3241ed /gcc | |
parent | 7804b4e24cd16283067225d4c2c4a4483a2b31bc (diff) | |
download | gcc-de0ab339a795352c843f6e9b2dfce222f26588de.zip gcc-de0ab339a795352c843f6e9b2dfce222f26588de.tar.gz gcc-de0ab339a795352c843f6e9b2dfce222f26588de.tar.bz2 |
tree-optimization/112827 - corrupt SCEV cache during SCCP
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr112827-1.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr112827-2.c | 18 | ||||
-rw-r--r-- | gcc/tree-scalar-evolution.cc | 9 |
3 files changed, 35 insertions, 6 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-1.c b/gcc/testsuite/gcc.dg/torture/pr112827-1.c new file mode 100644 index 0000000..6838cbb --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112827-1.c @@ -0,0 +1,14 @@ +/* { 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; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-2.c b/gcc/testsuite/gcc.dg/torture/pr112827-2.c new file mode 100644 index 0000000..a7a2a70 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112827-2.c @@ -0,0 +1,18 @@ +/* { 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; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 065bcd0..7556d89 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3847,13 +3847,10 @@ final_value_replacement_loop (class loop *loop) 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; |