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/102893 - properly DCE empty loops inside infinite loops
Date: Fri, 22 Oct 2021 13:42:52 +0200 (CEST)	[thread overview]
Message-ID: <rs8n479p-r1sp-138o-39qp-83788snon19p@fhfr.qr> (raw)

The following fixes the test for an exit edge I put in place for
the fix for PR45178 where I somehow misunderstood how the cyclic
list works.

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

2021-10-22  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/102893
	* tree-ssa-dce.c (find_obviously_necessary_stmts): Fix the
	test for an exit edge.

	* gcc.dg/tree-ssa/ssa-dce-9.c: New testcase.
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-9.c | 10 ++++++++++
 gcc/tree-ssa-dce.c                        |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-9.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-9.c
new file mode 100644
index 00000000000..e1ffa7f038d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-9.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
+
+int main()
+{
+  while(1)
+    for(int i=0; i<9000000; i++){}
+}
+
+/* { dg-final { scan-tree-dump-not "if" "cddce1" } } */
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index c4907af923c..372e0691ae6 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -436,7 +436,7 @@ find_obviously_necessary_stmts (bool aggressive)
 
       for (auto loop : loops_list (cfun, 0))
 	/* For loops without an exit do not mark any condition.  */
-	if (loop->exits->next && !finite_loop_p (loop))
+	if (loop->exits->next->e && !finite_loop_p (loop))
 	  {
 	    if (dump_file)
 	      fprintf (dump_file, "cannot prove finiteness of loop %i\n",
-- 
2.31.1

                 reply	other threads:[~2021-10-22 11:42 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=rs8n479p-r1sp-138o-39qp-83788snon19p@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).