From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] Make sure exported range for SSA post-dominates the DEF in set_global_ranges_from_unreachable_edges.
Date: Mon, 17 Oct 2022 20:56:18 +0200 [thread overview]
Message-ID: <20221017185618.78502-1-aldyh@redhat.com> (raw)
The problem here is that we're exporting a range for an SSA range that
happens on the other side of a __builtin_unreachable, but the SSA does
not post-dominate the definition point. This is causing ivcanon to
unroll things incorrectly.
This was a snafu when converting the code from evrp.
PR tree-optimization/107293
gcc/ChangeLog:
* tree-ssa-dom.cc
(dom_opt_dom_walker::set_global_ranges_from_unreachable_edges):
Check that condition post-dominates the definition point.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107293.c: New test.
---
gcc/testsuite/gcc.dg/tree-ssa/pr107293.c | 32 ++++++++++++++++++++++++
gcc/tree-ssa-dom.cc | 6 ++++-
2 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107293.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c
new file mode 100644
index 00000000000..724c31a11e6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c
@@ -0,0 +1,32 @@
+// { dg-do run }
+// { dg-options "-w -Os" }
+
+short a;
+int b[1];
+
+int c(int p) {
+ return (p < 0) ? 0 : 10 + ((p / 100 - 16) / 4);
+}
+
+void f(int n) {
+ while (1) {
+ int m = n;
+ while ((m ) )
+ m /= 2;
+ break;
+ }
+}
+
+void g() {
+ int h = a = 0;
+ for (; h + a <= 0; a++) {
+ if (b[c(a - 6)])
+ break;
+ f(a);
+ }
+}
+int main() {
+ g();
+ if (a != 1)
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index e6b8dace5e9..c7f095d79fc 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1367,7 +1367,11 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb)
tree name;
gori_compute &gori = m_ranger->gori ();
FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name)
- if (all_uses_feed_or_dominated_by_stmt (name, stmt))
+ if (all_uses_feed_or_dominated_by_stmt (name, stmt)
+ // The condition must post-dominate the definition point.
+ && (SSA_NAME_IS_DEFAULT_DEF (name)
+ || (gimple_bb (SSA_NAME_DEF_STMT (name))
+ == pred_e->src)))
{
Value_Range r (TREE_TYPE (name));
--
2.37.3
reply other threads:[~2022-10-17 18:56 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=20221017185618.78502-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--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).