https://gcc.gnu.org/g:0f774e452a421ebe448b16ccc16e56cdaaea546b

commit r17-5042-g0f774e452a421ebe448b16ccc16e56cdaaea546b
Author: Andrew MacLeod <[email protected]>
Date:   Fri Oct 9 13:03:29 2026 -0400

    Check frontier equivs for the free list.
    
    When adding the initial set of equivalences to the frontier search,
    we also need to make sure any equivalences are not in the FREE_LIST now.
    valid_equivs already checks this, it was an oversight not to check
    here.
    
            PR tree-optimization/127781
            gcc/
            * value-relation.cc (dom_oracle::start_search): Check if any equiv
            set elements are now in the free list.
    
            gcc/testsuite/
            * gcc.dg/pr127781.c: New.

Diff:
---
 gcc/testsuite/gcc.dg/pr127781.c | 47 +++++++++++++++++++++++++++++++++++++++++
 gcc/value-relation.cc           |  7 ++++--
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr127781.c b/gcc/testsuite/gcc.dg/pr127781.c
new file mode 100644
index 000000000000..eab72fbff159
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr127781.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+typedef struct { long size; const short *data; } SV;
+long findString(SV h, long from, SV n);
+
+static inline int checkSV(const SV *p)
+{
+    long k = 0;
+    for (long i = 0; i < p->size; ++i)
+        k += p->data[i] != 0;
+    return k == p->size && p->size < 100;
+}
+
+static inline long indexOf(const SV *h, SV n, long from)
+{
+    if (!checkSV(&n))
+        __builtin_unreachable();
+    if (!(from >= 0 && from <= h->size + 2))
+        __builtin_unreachable();
+    return findString(*h, from, n);
+}
+
+int scanForToken(const SV *h, SV sought)
+{
+    if (!checkSV(&sought))
+        __builtin_unreachable();
+    long n = sought.size;
+    if (!(n > 0))
+        __builtin_unreachable();
+    long idx = -n;
+    int count = 0;
+    while ((idx = indexOf(h, sought, idx + n)) >= 0)
+        ++count;
+    return count;
+}
+
+int scanForSigns(const SV *h)
+{
+    static const short minus[] = { 0x2212 };
+    static const short pair[] = { '-', '4' };
+    static const short hyph[] = { '-' };
+    const SV list[] = { { 1, minus }, { 2, pair }, { 1, hyph } };
+    int r = 0;
+    for (int i = 0; i < 3; ++i)
+        r = r * 10 + scanForToken(h, list[i]);
+    return r;
+}
diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index be4f1aaf784e..5fc781793688 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -1911,9 +1911,12 @@ dom_oracle::start_search (frontier_data &side, tree 
root, const_bitmap equiv,
   bitmap_iterator bi;
   EXECUTE_IF_SET_IN_BITMAP (equiv, 0, i, bi)
     {
-      if (i == root_v)
+      // Equivalences are maintained lazily, so ensure they are still
+      // valid before adding them to the frontier.
+      tree name = ssa_name (i);
+      if (i == root_v || !name || SSA_NAME_IN_FREE_LIST (name))
        continue;
-      m_worklist.safe_push ({ VREL_EQ, ssa_name (i), bb, side.m_rhs });
+      m_worklist.safe_push ({ VREL_EQ, name, bb, side.m_rhs });
       bitmap_set_bit (side.m_visited, i);
       side.set_known (i, VREL_EQ);
     }

Reply via email to