2019-08-30 Jakub Jelinek Backported from mainline 2019-02-05 Jakub Jelinek PR target/89188 * dce.c (delete_unmarked_insns): Don't remove no-op moves if they can throw, non-call exceptions are enabled and we can't delete dead exceptions or alter cfg. Set must_clean if delete_insn_and_edges returns true, don't set it blindly for calls. * g++.dg/opt/pr89188.C: New test. --- gcc/dce.c (revision 268646) +++ gcc/dce.c (revision 268647) @@ -577,7 +577,12 @@ delete_unmarked_insns (void) rtx turn_into_use = NULL_RTX; /* Always delete no-op moves. */ - if (noop_move_p (insn)) + if (noop_move_p (insn) + /* Unless the no-op move can throw and we are not allowed + to alter cfg. */ + && (!cfun->can_throw_non_call_exceptions + || (cfun->can_delete_dead_exceptions && can_alter_cfg) + || insn_nothrow_p (insn))) { if (RTX_FRAME_RELATED_P (insn)) turn_into_use @@ -620,12 +625,6 @@ delete_unmarked_insns (void) for the destination regs in order to avoid dangling notes. */ remove_reg_equal_equiv_notes_for_defs (insn); - /* If a pure or const call is deleted, this may make the cfg - have unreachable blocks. We rememeber this and call - delete_unreachable_blocks at the end. */ - if (CALL_P (insn)) - must_clean = true; - if (turn_into_use) { /* Don't remove frame related noop moves if they cary @@ -638,7 +637,7 @@ delete_unmarked_insns (void) } else /* Now delete the insn. */ - delete_insn_and_edges (insn); + must_clean |= delete_insn_and_edges (insn); } /* Deleted a pure or const call. */ --- gcc/testsuite/g++.dg/opt/pr89188.C (nonexistent) +++ gcc/testsuite/g++.dg/opt/pr89188.C (revision 268647) @@ -0,0 +1,13 @@ +// PR target/89188 +// { dg-do compile { target c++11 } } +// { dg-options "-Og -flive-range-shrinkage -fnon-call-exceptions" } + +struct Ax { + int n, a[]; +}; + +int i = 12345678; +int main() { + static Ax s{456, i}; + ((s.a[0]) ? (void)0 : (void)0); +}