From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/107876 - unswitching of switch
Date: Mon, 28 Nov 2022 10:04:33 +0100 (CET) [thread overview]
Message-ID: <20221128090434.44F5E13273@imap2.suse-dmz.suse.de> (raw)
The following shows a missed update of dominators when unswitching
removes unreachable edges from switch stmts it unswitches. Fixed
by wiping dominator info in that case.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/107876
* tree-ssa-loop-unswitch.cc (clean_up_after_unswitching): Wipe
dominator info if we removed an edge.
* g++.dg/tree-ssa/pr107876.C: New testcase.
---
gcc/testsuite/g++.dg/tree-ssa/pr107876.C | 38 ++++++++++++++++++++++++
gcc/tree-ssa-loop-unswitch.cc | 10 ++++++-
2 files changed, 47 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr107876.C
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr107876.C b/gcc/testsuite/g++.dg/tree-ssa/pr107876.C
new file mode 100644
index 00000000000..6cff2f1b166
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr107876.C
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O2 -funswitch-loops --param max-unswitch-insns=5 -fdump-tree-unswitch-details" }
+
+class X {
+public:
+ X();
+ X(const X&);
+ X(const volatile X &);
+ ~X();
+};
+
+X test17(int i) {
+ if (false) {
+ impossible:
+ if (i == 3)
+ return X();
+ }
+
+ while (true) {
+ X x;
+ if (i == 0)
+ return x;
+ if (i == 1)
+ break;
+ if (i == 2)
+ continue;
+ if (i == 3)
+ goto impossible;
+ if (i == 4)
+ __builtin_exit(1);
+ if (i == 5)
+ return x;
+ }
+ return X();
+}
+
+// { dg-final { scan-tree-dump "unswitching loop 1 on .switch. with condition: i_\[0-9\]+\\(D\\) == 2" "unswitch" } }
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index 186ae953f04..e8c9bd6812a 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -1631,6 +1631,7 @@ clean_up_after_unswitching (int ignored_edge_flag)
basic_block bb;
edge e;
edge_iterator ei;
+ bool removed_edge = false;
FOR_EACH_BB_FN (bb, cfun)
{
@@ -1655,7 +1656,10 @@ clean_up_after_unswitching (int ignored_edge_flag)
to preserve its edge. But we can remove the
non-default CASE sharing the edge. */
if (e != default_e)
- remove_edge (e);
+ {
+ remove_edge (e);
+ removed_edge = true;
+ }
}
else
{
@@ -1672,6 +1676,10 @@ clean_up_after_unswitching (int ignored_edge_flag)
FOR_EACH_EDGE (e, ei, bb->succs)
e->flags &= ~ignored_edge_flag;
}
+
+ /* If we removed an edge we possibly have to recompute dominators. */
+ if (removed_edge)
+ free_dominance_info (CDI_DOMINATORS);
}
/* Loop unswitching pass. */
--
2.35.3
reply other threads:[~2022-11-28 9:04 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=20221128090434.44F5E13273@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).