https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124272
Bug ID: 124272
Summary: unlink_stmt_vdef is sometimes not used with
release_ssa_name/release_defs
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: compile-time-hog, internal-improvement, memory-hog
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
I Noticed this while working on the ipa-fnsplit.cc patch.
We would leak some unused ssa names in this case.
gimple-ssa-sprintf.cc:
```
/* Remove the call to the bounded function with a zero size
(e.g., snprintf(0, 0, "%i", 123)) if there is no lhs. */
unlink_stmt_vdef (info.callstmt);
gsi_remove (gsi, true);
removed = true;
```
sanopt.cc:
```
{
unlink_stmt_vdef (use_stmt);
gimple_stmt_iterator gsi2 = gsi_for_stmt (use_stmt);
gsi_remove (&gsi2, true);
remove = true;
}
...
unlink_stmt_vdef (stmt);
gsi_remove (&gsi, true);
```
tree-eh.cc (cleanup_empty_eh_move_lp):
```
unlink_stmt_vdef (gsi_stmt (gsi));
gsi_remove (&gsi, true);
```
tree-parloops.cc (eliminate_local_variables_stmt):
```
unlink_stmt_vdef (stmt);
stmt = gimple_build_nop ();
gsi_replace (gsi, stmt, false);
dta.changed = true;
```
tree-ssa-dse.cc (delete_dead_or_redundant_call) (Just the first one, the second
is fine with release_defs):
```
if (lhs)
{
tree ptr = gimple_call_arg (stmt, 0);
gimple *new_stmt = gimple_build_assign (lhs, ptr);
unlink_stmt_vdef (stmt);
if (gsi_replace (gsi, new_stmt, true))
bitmap_set_bit (need_eh_cleanup, bb->index);
}
else
{
/* Then we need to fix the operand of the consuming stmt. */
unlink_stmt_vdef (stmt);
/* Remove the dead store. */
if (gsi_remove (gsi, true))
bitmap_set_bit (need_eh_cleanup, bb->index);
release_defs (stmt);
}
```
tree-ssa-forwprop.cc (optimize_vector_load) (double check this one):
```
gimple_stmt_iterator gsi2 = gsi_for_stmt (use_stmt);
unlink_stmt_vdef (use_stmt);
gsi_remove (&gsi2, true);
}
```
tree-ssa-phiprop.cc:
```
/* Unlinking the VDEF here is fine as we are sure that we process
stmts in execution order due to aggregate copies having VDEFs
and we emit loads on the edges in the very same order.
We get multiple copies (or intermediate register loads) handled
only by walking PHIs or immediate uses in a lucky order though,
so we could signal the caller to re-start iterating over PHIs
when we come here which would make it quadratic in the number
of PHIs. */
unlink_stmt_vdef (use_stmt);
gsi_remove (&gsi, true);
```
tree-ssa-strlen.cc (handle_builtin_memset) (like the tree-ssa-dse.cc one):
```
unlink_stmt_vdef (memset_stmt);
if (lhs)
{
gimple *assign = gimple_build_assign (lhs, ptr);
gsi_replace (&m_gsi, assign, false);
}
else
{
gsi_remove (&m_gsi, true);
release_defs (memset_stmt);
}
```
tree-vect-slp.cc (vect_remove_slp_scalar_calls):
```
unlink_stmt_vdef (stmt_info->stmt);
gsi = gsi_for_stmt (stmt);
vinfo->replace_stmt (&gsi, stmt_info, new_stmt);
if (lhs)
SSA_NAME_DEF_STMT (lhs) = new_stmt;
```
tree-vectorizer.cc (adjust_simduid_builtins):
```
case IFN_GOMP_SIMD_ORDERED_START:
case IFN_GOMP_SIMD_ORDERED_END:
if (integer_onep (gimple_call_arg (stmt, 0)))
{
enum built_in_function bcode
= (ifn == IFN_GOMP_SIMD_ORDERED_START
? BUILT_IN_GOMP_ORDERED_START
: BUILT_IN_GOMP_ORDERED_END);
gimple *g
= gimple_build_call (builtin_decl_explicit (bcode), 0);
gimple_move_vops (g, stmt);
gsi_replace (&i, g, true);
continue;
}
gsi_remove (&i, true);
unlink_stmt_vdef (stmt);
continue;
```
ubsan.cc (ubsan_expand_bounds_ifn):
```
/* Get rid of the UBSAN_BOUNDS call from the IR. */
unlink_stmt_vdef (stmt);
gsi_remove (&gsi_orig, true);
```
(ubsan_expand_null_ifn):
```
gsi_remove (gsip, true);
/* Unlink the UBSAN_NULLs vops before replacing it. */
unlink_stmt_vdef (stmt);
return true;
...
gimple_stmt_iterator gsi2 = gsi_start_bb (then_bb);
gimple_set_location (g, loc);
gsi_insert_after (&gsi2, g, GSI_NEW_STMT);
/* Unlink the UBSAN_NULLs vops before replacing it. */
unlink_stmt_vdef (stmt);
```
ubsan_expand_ptr_ifn
Check the ones in tree-ssa.cc (calls update_stmt afterwards which might release
it).
Check the one in omp-offload.cc .
Check the one in tree-ssa-sccvn.cc.