public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Subject: [COMMITTED] Return VARYING in range_on_path_entry if nothing found.
Date: Tue, 28 Sep 2021 11:12:01 +0200	[thread overview]
Message-ID: <20210928091200.867893-1-aldyh@redhat.com> (raw)

The problem here is that the solver's code solving unknown SSAs on entry
to a path was returning UNDEFINED if there were no incoming edges to the
start of the path that were not the function entry block.  This caused a
cascade of pain down stream.

Tested on x86-64 Linux.

	PR tree-optimization/102511

gcc/ChangeLog:

	* gimple-range-path.cc (path_range_query::range_on_path_entry):
	Return VARYING when nothing found.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102511.c: New test.
	* gcc.dg/tree-ssa/ssa-dom-thread-14.c: Adjust.
---
 gcc/gimple-range-path.cc                      | 11 +++++++++-
 gcc/testsuite/gcc.dg/pr102511.c               | 21 +++++++++++++++++++
 .../gcc.dg/tree-ssa/ssa-dom-thread-14.c       |  2 +-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr102511.c

diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index 71e04e4deba..9da67d2a35b 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -136,14 +136,23 @@ path_range_query::range_on_path_entry (irange &r, tree name)
 {
   int_range_max tmp;
   basic_block entry = entry_bb ();
+  bool changed = false;
+
   r.set_undefined ();
   for (unsigned i = 0; i < EDGE_COUNT (entry->preds); ++i)
     {
       edge e = EDGE_PRED (entry, i);
       if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
 	  && m_ranger.range_on_edge (tmp, e, name))
-	r.union_ (tmp);
+	{
+	  r.union_ (tmp);
+	  changed = true;
+	}
     }
+
+  // Make sure we don't return UNDEFINED by mistake.
+  if (!changed)
+    r.set_varying (TREE_TYPE (name));
 }
 
 // Return the range of NAME at the end of the path being analyzed.
diff --git a/gcc/testsuite/gcc.dg/pr102511.c b/gcc/testsuite/gcc.dg/pr102511.c
new file mode 100644
index 00000000000..8a9af347305
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr102511.c
@@ -0,0 +1,21 @@
+// { dg-do run }
+// { dg-options "-O3" }
+
+char arr_15 [8];
+__attribute__((noipa))
+void test(signed char a, unsigned short b, unsigned long long c,
+          unsigned short f) {
+  for (int d = b - 8; d < b; d += 2)
+    for (short e = 0; e < (unsigned short)((f ? 122 : 0) ^ (a ? c : 0)) - 64055;
+         e += 3)
+      arr_15[d] = 42;
+}
+int main() {
+    test(37, 8, 12325048486467861044ULL, 45936);
+    for (int i = 0; i < 8; ++i)
+      {
+        if (arr_15[i] != ((i&1) ? 0 : 42))
+          __builtin_abort();
+      }
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c
index 3bc4b3795cb..a25fe8bd89e 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c
@@ -37,5 +37,5 @@ expand_shift_1 (int code, int unsignedp, int rotate,
    we will enter the TRUE arm of the conditional and we can thread
    the test to compute the first first argument of the expand_binop
    call if we look backwards through the boolean logicals.  */
-/* { dg-final { scan-tree-dump-times "Threaded" 1 "dom2"} } */
+/* { dg-final { scan-tree-dump-times "Threaded" 2 "dom2"} } */
 
-- 
2.31.1


                 reply	other threads:[~2021-09-28  9:12 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=20210928091200.867893-1-aldyh@redhat.com \
    --to=aldyh@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).