https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105091
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org Status|UNCONFIRMED |ASSIGNED Ever confirmed|0 |1 Last reconfirmed| |2022-03-30 --- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> --- <bb 3> [local count: 715863673]: # ivtmp_47 = PHI <1(3), 2(2)> _43 = ivtmp_47 * 18446744073709551544; GOTMP.8 = MEM[(struct *)&GOTMP.5 + 144B + _43 * 1]; GOTMP.13 = GOTMP.8; test = GOTMP.13; p = test.x; D.483.__type_descriptor = &g.type.._6_7int; GOTMP.14 = p; D.483.__object = &GOTMP.14; main.F (D.483); p ={v} {CLOBBER(eol)}; if (ivtmp_47 != 1) goto <bb 3>; [66.67%] else goto <bb 4>; [33.33%] <bb 4> [local count: 357878152]: test ={v} {CLOBBER(eol)}; return; that's an interesting sequence of aggregate copies (meh - SRA should optimize those!) and an interesting choice of IVs but nothing invalid. We expand the GOTMP.8 = MEM[(struct *)&GOTMP.5 + 144B + _43 * 1]; stmt to memcpy() but GOTMP.5 is not TREE_ADDRESSABLE here. That might in the end lead DSE to remove the stores. When setting the flag inside gdb during expansion I see the stores are retained. Now, emit_block_op_via_libcall does /* Since dst and src are passed to a libcall, mark the corresponding tree EXPR as addressable. */ tree dst_expr = MEM_EXPR (dst); tree src_expr = MEM_EXPR (src); if (dst_expr) mark_addressable (dst_expr); if (src_expr) mark_addressable (src_expr); but mark_addressable doesn't handle TARGET_MEM_REF. Does the following fix the runtime error? The RTL after DSE seems to be OK. diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc index f9a650b5daf..5faaf43eaf5 100644 --- a/gcc/gimple-expr.cc +++ b/gcc/gimple-expr.cc @@ -910,7 +910,8 @@ mark_addressable (tree x) x = TREE_OPERAND (x, 0); while (handled_component_p (x)) x = TREE_OPERAND (x, 0); - if (TREE_CODE (x) == MEM_REF + if ((TREE_CODE (x) == MEM_REF + || TREE_CODE (x) == TARGET_MEM_REF) && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR) x = TREE_OPERAND (TREE_OPERAND (x, 0), 0); if (!VAR_P (x)