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/107301 - check if we can duplicate block before doing so
Date: Tue, 18 Oct 2022 10:30:21 +0200 (CEST)	[thread overview]
Message-ID: <20221018083022.2B11F139D2@imap2.suse-dmz.suse.de> (raw)

Path isolation failed to do that.

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

	PR tree-optimization/107301
	* gimple-ssa-isolate-paths.cc (handle_return_addr_local_phi_arg):
	Check whether we can duplicate the block.
	(find_implicit_erroneous_behavior): Likewise.

	* gcc.dg/torture/pr107301.c: New testcase.
---
 gcc/gimple-ssa-isolate-paths.cc         |  6 ++++--
 gcc/testsuite/gcc.dg/torture/pr107301.c | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr107301.c

diff --git a/gcc/gimple-ssa-isolate-paths.cc b/gcc/gimple-ssa-isolate-paths.cc
index 87ecd19ef4a..e4a4e08f549 100644
--- a/gcc/gimple-ssa-isolate-paths.cc
+++ b/gcc/gimple-ssa-isolate-paths.cc
@@ -647,7 +647,8 @@ handle_return_addr_local_phi_arg (basic_block bb, basic_block duplicate,
       if (!maybe
 	  && (flag_isolate_erroneous_paths_dereference
 	      || flag_isolate_erroneous_paths_attribute)
-	  && gimple_bb (use_stmt) == bb)
+	  && gimple_bb (use_stmt) == bb
+	  && (duplicate || can_duplicate_block_p (bb)))
 	{
 	  duplicate = isolate_path (bb, duplicate, e,
 				    use_stmt, lhs, true);
@@ -765,7 +766,8 @@ find_implicit_erroneous_behavior (void)
 		    ? gimple_location (use_stmt)
 		    : phi_arg_loc;
 
-		  if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc))
+		  if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc)
+		      && (duplicate || can_duplicate_block_p (bb)))
 		    {
 		      duplicate = isolate_path (bb, duplicate, e,
 						use_stmt, lhs, false);
diff --git a/gcc/testsuite/gcc.dg/torture/pr107301.c b/gcc/testsuite/gcc.dg/torture/pr107301.c
new file mode 100644
index 00000000000..5f0afcc0d10
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr107301.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+__attribute__ ((pure, returns_twice)) int
+foo (int x)
+{
+  int a;
+
+  a = x ? 3 : 0;
+  x /= a;
+  a = foo (x);
+  if (x == a)
+    __builtin_unreachable ();
+
+  return 0;
+}
-- 
2.35.3

                 reply	other threads:[~2022-10-18  8:30 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=20221018083022.2B11F139D2@imap2.suse-dmz.suse.de \
    --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).