public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/96491 - avoid store commoning across abnormal edges
Date: Thu, 6 Aug 2020 12:20:35 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.YFH.7.76.2008061220190.9963@zhemvz.fhfr.qr> (raw)

This avoids store commoning across abnormal edges since that easily
can disrupt abnormal coalescing because it might create overlapping
lifetime of variables.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2020-08-06  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/96491
	* tree-ssa-sink.c (sink_common_stores_to_bb): Avoid
	sinking across abnormal edges.

	* gcc.dg/torture/pr96491.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr96491.c | 29 ++++++++++++++++++++++++++
 gcc/tree-ssa-sink.c                    |  3 ++-
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr96491.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr96491.c b/gcc/testsuite/gcc.dg/torture/pr96491.c
new file mode 100644
index 00000000000..784559f4754
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr96491.c
@@ -0,0 +1,29 @@
+/* { dg-do compile }  */
+
+int rj;
+
+void __attribute__ ((returns_twice))
+da (void)
+{
+  rj = 1;
+}
+
+void
+c5 (void)
+{
+  for (;;)
+    ++rj;
+}
+
+void
+ls (int kz)
+{
+  if (kz == 0)
+    {
+      rj = 0;
+      c5 ();
+    }
+
+  da ();
+  c5 ();
+}
diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c
index 962ad076968..4cc5195f2f8 100644
--- a/gcc/tree-ssa-sink.c
+++ b/gcc/tree-ssa-sink.c
@@ -503,7 +503,8 @@ sink_common_stores_to_bb (basic_block bb)
 	      tree arg = gimple_phi_arg_def (phi, i);
 	      gimple *def = SSA_NAME_DEF_STMT (arg);
 	      if (! is_gimple_assign (def)
-		  || stmt_can_throw_internal (cfun, def))
+		  || stmt_can_throw_internal (cfun, def)
+		  || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL))
 		{
 		  /* ???  We could handle some cascading with the def being
 		     another PHI.  We'd have to insert multiple PHIs for
-- 
2.26.2

                 reply	other threads:[~2020-08-06 10:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.YFH.7.76.2008061220190.9963@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).