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 r14-4857] tree-optimization/111917 - bougs IL after guard hoisting
Date: Mon, 23 Oct 2023 10:35:03 +0000 (GMT)	[thread overview]
Message-ID: <20231023103503.E9F973858C3A@sourceware.org> (raw)

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

commit r14-4857-gd96bd4aade170fcd86f5f09b68b770dde798e631
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 23 11:25:17 2023 +0200

    tree-optimization/111917 - bougs IL after guard hoisting
    
    The unswitching code to hoist guards inserts conditions in wrong
    places.  The following fixes this, simplifying code.
    
            PR tree-optimization/111917
            * tree-ssa-loop-unswitch.cc (hoist_guard): Always insert
            new conditional after last stmt.
    
            * gcc.dg/torture/pr111917.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr111917.c | 23 +++++++++++++++++++++++
 gcc/tree-ssa-loop-unswitch.cc           |  5 +----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr111917.c b/gcc/testsuite/gcc.dg/torture/pr111917.c
new file mode 100644
index 000000000000..532e30200b59
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111917.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-funswitch-loops" } */
+
+long t;
+long a() {
+  long b = t, c = t;
+  for (; b < 31; b++)
+    c <<= 1;
+  return c;
+}
+long t1;
+static
+int d() {
+  if (!t1)
+    return 0;
+e:
+f:
+  for (; a();)
+    ;
+  goto f;
+  return 0;
+}
+int main() { d(); }
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index 619b50fb4bb0..b4611ac82561 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -1455,10 +1455,7 @@ hoist_guard (class loop *loop, edge guard)
   cond_stmt = as_a <gcond *> (stmt);
   extract_true_false_edges_from_block (guard_bb, &te, &fe);
   /* Insert guard to PRE_HEADER.  */
-  if (!empty_block_p (pre_header))
-    gsi = gsi_last_bb (pre_header);
-  else
-    gsi = gsi_start_bb (pre_header);
+  gsi = gsi_last_bb (pre_header);
   /* Create copy of COND_STMT.  */
   new_cond_stmt = gimple_build_cond (gimple_cond_code (cond_stmt),
 				     gimple_cond_lhs (cond_stmt),

                 reply	other threads:[~2023-10-23 10:35 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=20231023103503.E9F973858C3A@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).