* [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
@ 2019-01-16 22:43 Jakub Jelinek
2019-01-16 22:48 ` Jeff Law
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2019-01-16 22:43 UTC (permalink / raw)
To: Richard Biener, Eric Botcazou; +Cc: gcc-patches
Hi!
For normal instructions, deletable_insn_p has:
/* Don't delete insns that may throw if we cannot do so. */
if (!(cfun->can_delete_dead_exceptions && can_alter_cfg)
&& !insn_nothrow_p (insn))
return false;
The following patch adds that for the const/pure non-looping calls
that are handled earlier in the function as well (I haven't moved this test
earlier so we don't check insn_nothrow_p on jump insns etc.).
The other change is just to handle those calls the same as non-const/pure,
if we never consider them to be deletable, there is no point in
find_call_stack_args for them, like we don't do that for normal calls.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2019-01-16 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/88870
* dce.c (deletable_insn_p): Never delete const/pure calls that can
throw if we can't alter the cfg or delete dead exceptions.
(mark_insn): Don't call find_call_stack_args for such calls.
* gcc.dg/pr88870.c: New test.
--- gcc/dce.c.jj 2019-01-01 12:37:21.308906844 +0100
+++ gcc/dce.c 2019-01-16 11:39:13.432604633 +0100
@@ -108,7 +108,10 @@ deletable_insn_p (rtx_insn *insn, bool f
/* We can delete dead const or pure calls as long as they do not
infinite loop. */
&& (RTL_CONST_OR_PURE_CALL_P (insn)
- && !RTL_LOOPING_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)))
return find_call_stack_args (as_a <rtx_call_insn *> (insn), false,
fast, arg_stores);
@@ -201,7 +204,9 @@ mark_insn (rtx_insn *insn, bool fast)
&& !df_in_progress
&& !SIBLING_CALL_P (insn)
&& (RTL_CONST_OR_PURE_CALL_P (insn)
- && !RTL_LOOPING_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)))
find_call_stack_args (as_a <rtx_call_insn *> (insn), true, fast, NULL);
}
}
--- gcc/testsuite/gcc.dg/pr88870.c.jj 2019-01-16 11:25:01.434552788 +0100
+++ gcc/testsuite/gcc.dg/pr88870.c 2019-01-16 11:24:48.172769383 +0100
@@ -0,0 +1,23 @@
+/* PR rtl-optimization/88870 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fexceptions -fnon-call-exceptions -ftrapv -fno-tree-dominator-opts" } */
+
+int a, b;
+
+void
+foo (int *x)
+{
+ int c = 0;
+ {
+ int d;
+ x = &c;
+ for (;;)
+ {
+ x = &d;
+ b = 0;
+ d = c + 1;
+ b = c = 1;
+ ++a;
+ }
+ }
+}
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
2019-01-16 22:43 [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870) Jakub Jelinek
@ 2019-01-16 22:48 ` Jeff Law
2019-01-16 22:51 ` Jakub Jelinek
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2019-01-16 22:48 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener, Eric Botcazou; +Cc: gcc-patches
On 1/16/19 3:43 PM, Jakub Jelinek wrote:
> Hi!
>
> For normal instructions, deletable_insn_p has:
> /* Don't delete insns that may throw if we cannot do so. */
> if (!(cfun->can_delete_dead_exceptions && can_alter_cfg)
> && !insn_nothrow_p (insn))
> return false;
>
> The following patch adds that for the const/pure non-looping calls
> that are handled earlier in the function as well (I haven't moved this test
> earlier so we don't check insn_nothrow_p on jump insns etc.).
>
> The other change is just to handle those calls the same as non-const/pure,
> if we never consider them to be deletable, there is no point in
> find_call_stack_args for them, like we don't do that for normal calls.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2019-01-16 Jakub Jelinek <jakub@redhat.com>
>
> PR rtl-optimization/88870
> * dce.c (deletable_insn_p): Never delete const/pure calls that can
> throw if we can't alter the cfg or delete dead exceptions.
> (mark_insn): Don't call find_call_stack_args for such calls.
>
> * gcc.dg/pr88870.c: New test.
OK. Though I wonder if we want to continue to support
-fnon-call-exceptions. With GCJ gone is there any value left in that
capability? There's little doubt in my mind other parts of GCC are not
-fnon-call-exception safe.
jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
2019-01-16 22:48 ` Jeff Law
@ 2019-01-16 22:51 ` Jakub Jelinek
2019-01-17 7:59 ` Arnaud Charlet
2019-01-17 11:27 ` Eric Botcazou
0 siblings, 2 replies; 6+ messages in thread
From: Jakub Jelinek @ 2019-01-16 22:51 UTC (permalink / raw)
To: Jeff Law; +Cc: Richard Biener, Eric Botcazou, gcc-patches
On Wed, Jan 16, 2019 at 03:48:07PM -0700, Jeff Law wrote:
> > 2019-01-16 Jakub Jelinek <jakub@redhat.com>
> >
> > PR rtl-optimization/88870
> > * dce.c (deletable_insn_p): Never delete const/pure calls that can
> > throw if we can't alter the cfg or delete dead exceptions.
> > (mark_insn): Don't call find_call_stack_args for such calls.
> >
> > * gcc.dg/pr88870.c: New test.
> OK. Though I wonder if we want to continue to support
> -fnon-call-exceptions. With GCJ gone is there any value left in that
> capability? There's little doubt in my mind other parts of GCC are not
> -fnon-call-exception safe.
AFAIK Ada and Go use -fnon-call-exceptions by default and heavily rely on
it.
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
2019-01-16 22:51 ` Jakub Jelinek
@ 2019-01-17 7:59 ` Arnaud Charlet
2019-01-17 11:27 ` Eric Botcazou
1 sibling, 0 replies; 6+ messages in thread
From: Arnaud Charlet @ 2019-01-17 7:59 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jeff Law, Richard Biener, Eric Botcazou, gcc-patches
> > > PR rtl-optimization/88870
> > > * dce.c (deletable_insn_p): Never delete const/pure calls that can
> > > throw if we can't alter the cfg or delete dead exceptions.
> > > (mark_insn): Don't call find_call_stack_args for such calls.
> > >
> > > * gcc.dg/pr88870.c: New test.
> > OK. Though I wonder if we want to continue to support
> > -fnon-call-exceptions. With GCJ gone is there any value left in that
> > capability? There's little doubt in my mind other parts of GCC are not
> > -fnon-call-exception safe.
>
> AFAIK Ada and Go use -fnon-call-exceptions by default and heavily rely on
> it.
Agreed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
2019-01-16 22:51 ` Jakub Jelinek
2019-01-17 7:59 ` Arnaud Charlet
@ 2019-01-17 11:27 ` Eric Botcazou
2019-01-17 11:33 ` Jakub Jelinek
1 sibling, 1 reply; 6+ messages in thread
From: Eric Botcazou @ 2019-01-17 11:27 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jeff Law, Richard Biener, gcc-patches
> AFAIK Ada and Go use -fnon-call-exceptions by default and heavily rely on
> it.
Right, the Ada compiler uses -fnon-call-exceptions -fdelete-dead-exceptions
and ACATS could not be passed with optimization enabled without the former.
Btw, there are a couple of improper direct uses of flag_non_call_exceptions in
the sources, may I change them to cfun->can_throw_non_call_exceptions?
gimple-ssa-isolate-paths.c: if (!flag_non_call_exceptions)
gimple-ssa-isolate-paths.c: if (!flag_non_call_exceptions
tree-ssa-alias.c: if (flag_non_call_exceptions && pi->pt.null)
--
Eric Botcazou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870)
2019-01-17 11:27 ` Eric Botcazou
@ 2019-01-17 11:33 ` Jakub Jelinek
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2019-01-17 11:33 UTC (permalink / raw)
To: Eric Botcazou; +Cc: Jeff Law, Richard Biener, gcc-patches
On Thu, Jan 17, 2019 at 12:27:31PM +0100, Eric Botcazou wrote:
> > AFAIK Ada and Go use -fnon-call-exceptions by default and heavily rely on
> > it.
>
> Right, the Ada compiler uses -fnon-call-exceptions -fdelete-dead-exceptions
> and ACATS could not be passed with optimization enabled without the former.
>
> Btw, there are a couple of improper direct uses of flag_non_call_exceptions in
> the sources, may I change them to cfun->can_throw_non_call_exceptions?
Yes.
> gimple-ssa-isolate-paths.c: if (!flag_non_call_exceptions)
> gimple-ssa-isolate-paths.c: if (!flag_non_call_exceptions
> tree-ssa-alias.c: if (flag_non_call_exceptions && pi->pt.null)
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-17 11:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-16 22:43 [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870) Jakub Jelinek
2019-01-16 22:48 ` Jeff Law
2019-01-16 22:51 ` Jakub Jelinek
2019-01-17 7:59 ` Arnaud Charlet
2019-01-17 11:27 ` Eric Botcazou
2019-01-17 11:33 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).