public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-9211] tree-optimization/97627 - Avoid computing niters for fake edges
Date: Fri, 29 Jan 2021 11:51:27 +0000 (GMT)	[thread overview]
Message-ID: <20210129115127.2040A384B824@sourceware.org> (raw)

https://gcc.gnu.org/g:a7e6e7a9299208e5aa3d805d502370d59f92b8b5

commit r9-9211-ga7e6e7a9299208e5aa3d805d502370d59f92b8b5
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 29 11:17:42 2021 +0100

    tree-optimization/97627 - Avoid computing niters for fake edges
    
    This avoids computing niters information for fake edges.
    
    2021-01-29  Bin Cheng  <bin.cheng@linux.alibaba.com>
                Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/97627
            * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions):
            Do not analyze fake edges.
    
            * g++.dg/pr97627.C: New testcase.
    
    (cherry picked from commit 3976b2701b826569ffcd90877d94095def507e3f)

Diff:
---
 gcc/testsuite/g++.dg/pr97627.C | 44 ++++++++++++++++++++++++++++++++++++++++++
 gcc/tree-ssa-loop-niter.c      |  5 +++++
 2 files changed, 49 insertions(+)

diff --git a/gcc/testsuite/g++.dg/pr97627.C b/gcc/testsuite/g++.dg/pr97627.C
new file mode 100644
index 00000000000..81466dc3b81
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr97627.C
@@ -0,0 +1,44 @@
+/* PR tree-optimization/97627.  */
+/* { dg-do run } */
+
+struct S { unsigned short x, y; } m = { 1, 0 };
+
+__attribute__((noipa)) void
+baz (int x, int y)
+{
+  if (x != 0 || y != 1)
+    __builtin_abort ();
+}
+
+__attribute__((noipa)) void
+bar ()
+{
+  throw 1;
+}
+
+void
+foo ()
+{
+  while (1)
+    {
+      int a = m.x + 1;
+      int b = m.y + 1;
+      for (int c = 0; c < a; c++)
+	for (int d = 0; d < b; d++)
+	  baz (d, b);
+      bar ();
+    }
+}
+
+int
+main ()
+{
+  try
+    {
+      foo ();
+    }
+  catch (int)
+    {
+    }
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 470b6a295be..200344b42dd 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2382,6 +2382,11 @@ number_of_iterations_exit_assumptions (struct loop *loop, edge exit,
   affine_iv iv0, iv1;
   bool safe;
 
+  /* The condition at a fake exit (if it exists) does not control its
+     execution.  */
+  if (exit->flags & EDGE_FAKE)
+    return false;
+
   /* Nothing to analyze if the loop is known to be infinite.  */
   if (loop_constraint_set_p (loop, LOOP_C_INFINITE))
     return false;


                 reply	other threads:[~2021-01-29 11:51 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=20210129115127.2040A384B824@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@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).