public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Perform cfg cleanup in cse if needed (PR rtl-optimization/92610)
@ 2019-11-23  2:11 Jakub Jelinek
  2019-11-23  6:56 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-11-23  2:11 UTC (permalink / raw)
  To: Jeff Law, Richard Biener, Eric Botcazou; +Cc: gcc-patches

Hi!

cse_main which sets tem has:
  if (cse_jumps_altered || recorded_label_ref)
    return 2;
  else if (cse_cfg_altered)
    return 1;
  else
    return 0;
at the end, but after these two functions call it, they call also
delete_trivially_dead_insns.  Even when cse_main didn't need cfg changes,
delete_trivially_dead_insns could remove a trivially dead insn that had
EH edges and so we might still need to remove unreachable blocks.

The following patch implements it.  Bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?

2019-11-23  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/92610
	* cse.c (rest_of_handle_cse2): Call cleanup_cfg (0) also if
	cse_cfg_altered is set, even when tem is 0.
	(rest_of_handle_cse_after_global_opts): Likewise.

	* g++.dg/opt/pr92610.C: New test.

--- gcc/cse.c.jj	2019-11-19 22:27:01.960059340 +0100
+++ gcc/cse.c	2019-11-22 15:51:34.639806155 +0100
@@ -7701,7 +7701,7 @@ rest_of_handle_cse2 (void)
       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
       timevar_pop (TV_JUMP);
     }
-  else if (tem == 1)
+  else if (tem == 1 || cse_cfg_altered)
     cse_cfg_altered |= cleanup_cfg (0);
 
   cse_not_expected = 1;
@@ -7775,7 +7775,7 @@ rest_of_handle_cse_after_global_opts (vo
       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
       timevar_pop (TV_JUMP);
     }
-  else if (tem == 1)
+  else if (tem == 1 || cse_cfg_altered)
     cse_cfg_altered |= cleanup_cfg (0);
 
   flag_cse_follow_jumps = save_cfj;
--- gcc/testsuite/g++.dg/opt/pr92610.C.jj	2019-11-22 15:52:46.254734331 +0100
+++ gcc/testsuite/g++.dg/opt/pr92610.C	2019-11-22 15:53:14.991303498 +0100
@@ -0,0 +1,13 @@
+// PR rtl-optimization/92610
+// { dg-do compile }
+// { dg-options "-w -fdelete-dead-exceptions --param=sccvn-max-alias-queries-per-access=0 -fno-dse -fnon-call-exceptions -Os -funroll-loops -ftrapv" }
+
+struct C { int x; ~C () {} };
+
+int
+main ()
+{
+  C *buffer = new C[42];
+  buffer[-3].x = 42;
+  delete [] buffer;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Perform cfg cleanup in cse if needed (PR rtl-optimization/92610)
  2019-11-23  2:11 [PATCH] Perform cfg cleanup in cse if needed (PR rtl-optimization/92610) Jakub Jelinek
@ 2019-11-23  6:56 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2019-11-23  6:56 UTC (permalink / raw)
  To: Jakub Jelinek, Jeff Law, Eric Botcazou; +Cc: gcc-patches

On November 23, 2019 2:15:36 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>cse_main which sets tem has:
>  if (cse_jumps_altered || recorded_label_ref)
>    return 2;
>  else if (cse_cfg_altered)
>    return 1;
>  else
>    return 0;
>at the end, but after these two functions call it, they call also
>delete_trivially_dead_insns.  Even when cse_main didn't need cfg
>changes,
>delete_trivially_dead_insns could remove a trivially dead insn that had
>EH edges and so we might still need to remove unreachable blocks.
>
>The following patch implements it.  Bootstrapped/regtested on
>x86_64-linux
>and i686-linux, ok for trunk?

Ok. 

Richard. 

>2019-11-23  Jakub Jelinek  <jakub@redhat.com>
>
>	PR rtl-optimization/92610
>	* cse.c (rest_of_handle_cse2): Call cleanup_cfg (0) also if
>	cse_cfg_altered is set, even when tem is 0.
>	(rest_of_handle_cse_after_global_opts): Likewise.
>
>	* g++.dg/opt/pr92610.C: New test.
>
>--- gcc/cse.c.jj	2019-11-19 22:27:01.960059340 +0100
>+++ gcc/cse.c	2019-11-22 15:51:34.639806155 +0100
>@@ -7701,7 +7701,7 @@ rest_of_handle_cse2 (void)
>       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
>       timevar_pop (TV_JUMP);
>     }
>-  else if (tem == 1)
>+  else if (tem == 1 || cse_cfg_altered)
>     cse_cfg_altered |= cleanup_cfg (0);
> 
>   cse_not_expected = 1;
>@@ -7775,7 +7775,7 @@ rest_of_handle_cse_after_global_opts (vo
>       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
>       timevar_pop (TV_JUMP);
>     }
>-  else if (tem == 1)
>+  else if (tem == 1 || cse_cfg_altered)
>     cse_cfg_altered |= cleanup_cfg (0);
> 
>   flag_cse_follow_jumps = save_cfj;
>--- gcc/testsuite/g++.dg/opt/pr92610.C.jj	2019-11-22 15:52:46.254734331
>+0100
>+++ gcc/testsuite/g++.dg/opt/pr92610.C	2019-11-22 15:53:14.991303498
>+0100
>@@ -0,0 +1,13 @@
>+// PR rtl-optimization/92610
>+// { dg-do compile }
>+// { dg-options "-w -fdelete-dead-exceptions
>--param=sccvn-max-alias-queries-per-access=0 -fno-dse
>-fnon-call-exceptions -Os -funroll-loops -ftrapv" }
>+
>+struct C { int x; ~C () {} };
>+
>+int
>+main ()
>+{
>+  C *buffer = new C[42];
>+  buffer[-3].x = 42;
>+  delete [] buffer;
>+}
>
>	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-23  6:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-23  2:11 [PATCH] Perform cfg cleanup in cse if needed (PR rtl-optimization/92610) Jakub Jelinek
2019-11-23  6:56 ` Richard Biener

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).