https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92262
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Actually I can, but for some reason I had to use explicit -fchecking, dunno how I've configured this cross. Anyway, I don't see a tree sharing issue in the newly added code, but get_computation_at doesn't unshare, which can be perhaps ok with the way it is used in non-debug stmts, but it is not ok for debug stmts. Now, we could unshare_expr in get_debug_computation_at when get_computation_at succeeds, but as we now iterate over possibly several IVs, I think it is better to unshare only when we pick the best candidate. So: --- gcc/tree-ssa-loop-ivopts.c.jj 2019-10-23 14:35:42.994753407 +0200 +++ gcc/tree-ssa-loop-ivopts.c 2019-10-29 09:45:47.418217336 +0100 @@ -4152,8 +4152,6 @@ get_debug_computation_at (class loop *lo var = fold_convert (ctype, var); } - ubase = unshare_expr (ubase); - cbase = unshare_expr (cbase); if (stmt_after_increment (loop, cand, at)) var = fold_build2 (MINUS_EXPR, TREE_TYPE (var), var, unshare_expr (cstep)); @@ -7648,6 +7646,7 @@ remove_unused_ivs (struct ivopts_data *d if (!best_cand) continue; + comp = unshare_expr (comp); if (count > 1) { tree vexpr = make_node (DEBUG_EXPR_DECL);