aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr122497-1.c13
-rw-r--r--gcc/tree-scalar-evolution.cc10
2 files changed, 18 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr122497-1.c b/gcc/testsuite/gcc.dg/torture/pr122497-1.c
new file mode 100644
index 0000000..8b027ca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr122497-1.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* PR tree-optimization/122497 */
+
+/* This was ICEing during SCCP
+ trying to simplify a reference back to the phi
+ which was removed. */
+
+char g_2[1][2];
+int g_4, g_5;
+void main() {
+ for (; g_4; g_4 -= 1)
+ g_5 = g_2[g_4 + 2][g_4];
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index ecdef75..7907893 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3949,11 +3949,6 @@ final_value_replacement_loop (class loop *loop)
auto loc = gimple_phi_arg_location (phi, exit->dest_idx);
remove_phi_node (&psi, false);
- /* Propagate constants immediately, but leave an unused initialization
- around to avoid invalidating the SCEV cache. */
- if (CONSTANT_CLASS_P (def) && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rslt))
- replace_uses_by (rslt, def);
-
/* Create the replacement statements. */
gimple_seq stmts;
def = force_gimple_operand (def, &stmts, false, NULL_TREE);
@@ -3961,6 +3956,11 @@ final_value_replacement_loop (class loop *loop)
gimple_set_location (ass, loc);
gimple_seq_add_stmt (&stmts, ass);
+ /* Propagate constants immediately, but leave an unused initialization
+ around to avoid invalidating the SCEV cache. */
+ if (CONSTANT_CLASS_P (def) && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rslt))
+ replace_uses_by (rslt, def);
+
/* If def's type has undefined overflow and there were folded
casts, rewrite all stmts added for def into arithmetics
with defined overflow behavior. */