]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/112827 - more SCEV cprop fixes
authorRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2023 14:46:38 +0000 (15:46 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 5 Dec 2023 07:26:04 +0000 (08:26 +0100)
The insert iteration can be corrupted by foldings of replace_uses_by,
within this particular PHI replacement but also with subsequent ones.
Recompute the insert location before insertion instead.

This fixes an obvserved ICE of gcc.dg/tree-ssa/ssa-sink-16.c.

PR tree-optimization/112827
PR tree-optimization/112848
* tree-scalar-evolution.cc (final_value_replacement_loop):
Compute the insert location for each insert.

gcc/tree-scalar-evolution.cc

index 7556d89e9f8891a25bff943fd88efe09be467312..385fc64ab8ca457027caa5a513a91a2cf08aef0f 100644 (file)
@@ -3739,7 +3739,6 @@ final_value_replacement_loop (class loop *loop)
     split_loop_exit_edge (exit);
 
   /* Set stmt insertion pointer.  All stmts are inserted before this point.  */
-  gimple_stmt_iterator gsi = gsi_after_labels (exit->dest);
 
   class loop *ex_loop
     = superloop_at_depth (loop,
@@ -3880,6 +3879,7 @@ final_value_replacement_loop (class loop *loop)
              gsi_next (&gsi2);
            }
        }
+      gimple_stmt_iterator gsi = gsi_after_labels (exit->dest);
       gsi_insert_seq_before (&gsi, stmts, GSI_SAME_STMT);
       if (dump_file)
        {