On Tue, 16 Apr 2019, Jakub Jelinek wrote: > Hi! > > Recently I've added an assert that if !can_alter_cfg DCE (fast DCE in that > case) doesn't actually alter the cfg. The following testcase shows > something where it still does. Even when a (const or pure) call doesn't > throw, it could have EDGE_ABNORMAL{,_CALL} edges added to setjmp etc. > The following patch makes sure we don't DCE such calls either if we can't > alter the cfg. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK. Richard. > 2019-04-16 Jakub Jelinek <ja...@redhat.com> > > PR rtl-optimization/90082 > * dce.c (can_delete_call): New function. > (deletable_insn_p, mark_insn): Use it. > > * gcc.dg/pr90082.c: New test. > > --- gcc/dce.c.jj 2019-04-12 18:19:47.134165696 +0200 > +++ gcc/dce.c 2019-04-15 12:17:40.746266503 +0200 > @@ -87,6 +87,32 @@ deletable_insn_p_1 (rtx body) > } > } > > +/* Don't delete calls that may throw if we cannot do so. */ > + > +static bool > +can_delete_call (rtx_insn *insn) > +{ > + if (cfun->can_delete_dead_exceptions && can_alter_cfg) > + return true; > + if (!insn_nothrow_p (insn)) > + return false; > + if (can_alter_cfg) > + return true; > + /* If we can't alter cfg, even when the call can't throw exceptions, it > + might have EDGE_ABNORMAL_CALL edges and so we shouldn't delete such > + calls. */ > + gcc_assert (CALL_P (insn)); > + if (BLOCK_FOR_INSN (insn) && BB_END (BLOCK_FOR_INSN (insn)) == insn) > + { > + edge e; > + edge_iterator ei; > + > + FOR_EACH_EDGE (e, ei, BLOCK_FOR_INSN (insn)->succs) > + if ((e->flags & EDGE_ABNORMAL_CALL) != 0) > + return false; > + } > + return true; > +} > > /* Return true if INSN is a normal instruction that can be deleted by > the DCE pass. */ > @@ -111,8 +137,7 @@ deletable_insn_p (rtx_insn *insn, bool f > && (RTL_CONST_OR_PURE_CALL_P (insn) > && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)) > /* Don't delete calls that may throw if we cannot do so. */ > - && ((cfun->can_delete_dead_exceptions && can_alter_cfg) > - || insn_nothrow_p (insn))) > + && can_delete_call (insn)) > return find_call_stack_args (as_a <rtx_call_insn *> (insn), false, > fast, arg_stores); > > @@ -206,8 +231,7 @@ mark_insn (rtx_insn *insn, bool fast) > && !SIBLING_CALL_P (insn) > && (RTL_CONST_OR_PURE_CALL_P (insn) > && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)) > - && ((cfun->can_delete_dead_exceptions && can_alter_cfg) > - || insn_nothrow_p (insn))) > + && can_delete_call (insn)) > find_call_stack_args (as_a <rtx_call_insn *> (insn), true, fast, NULL); > } > } > --- gcc/testsuite/gcc.dg/pr90082.c.jj 2019-04-15 12:22:01.662053468 +0200 > +++ gcc/testsuite/gcc.dg/pr90082.c 2019-04-15 12:22:41.638407968 +0200 > @@ -0,0 +1,13 @@ > +/* PR rtl-optimization/90082 */ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fnon-call-exceptions -ftrapv" } */ > + > +void *buf[5]; > + > +void > +foo (int a) > +{ > + if (__builtin_setjmp (buf) == 0) > + __asm__ ("" : : "n" (a * 2)); /* { dg-error "impossible constraint in > 'asm'" } */ > + /* { dg-warning "asm operand 0 probably > doesn't match constraints" "" { target *-*-* } .-1 } */ > +} > > Jakub > -- Richard Biener <rguent...@suse.de> SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG Nürnberg)