https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81245
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #5)
> Actually
>
> if (fold_stmt (...))
> update_stmt (gsi_stmt (new_gsi));
>
> is correct ;) The old update_stmt was redundant (gsi_insert_before updates
> the stmt already). fold_stmt may replace the stmt so with your fix you
> might just end up updating a stale one...
Yes, I agree and in fact my testing showed my patch did not work, I am testing
a new patch:
Index: tree-if-conv.c
===================================================================
--- tree-if-conv.c (revision 249769)
+++ tree-if-conv.c (working copy)
@@ -1853,7 +1853,8 @@
new_stmt = gimple_build_assign (res, rhs);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
gimple_stmt_iterator new_gsi = gsi_for_stmt (new_stmt);
- fold_stmt (&new_gsi, ifcvt_follow_ssa_use_edges);
+ if (fold_stmt (&new_gsi, ifcvt_follow_ssa_use_edges))
+ new_stmt = gsi_stmt (new_gsi);
update_stmt (new_stmt);
if (dump_file && (dump_flags & TDF_DETAILS))
---- CUT ----
This is so the print below has the correct statement when printing.