[COMMITTED] Kill second order relations in the path solver.

Message ID 20211027181323.395724-1-aldyh@redhat.com
State Committed
Commit 9f4edfc1fb80211f8663f978b7144e7e9d9df743
Headers
Series [COMMITTED] Kill second order relations in the path solver. |

Commit Message

Aldy Hernandez Oct. 27, 2021, 6:13 p.m. UTC
  My upcoming work replacing the VRP threaders with a fully resolving
backward threader has tripped over various corner cases in the path
sensitive relation oracle.  This patch kills second order relations when
we kill a relation.

Tested on x86-64 and ppc64le Linux.

Co-authored-by: Andrew MacLeod <amacleod@redhat.com>

gcc/ChangeLog:

	* value-relation.cc (path_oracle::killing_def): Kill second
	order relations.
---
 gcc/value-relation.cc | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Comments

Bernhard Reutner-Fischer Oct. 27, 2021, 11:55 p.m. UTC | #1
On Wed, 27 Oct 2021 20:13:21 +0200
Aldy Hernandez via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:

[would have to think about this some more but it's late here. Nits:]

> diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
> index 2acf375ca9a..0ad4f7a9495 100644
> --- a/gcc/value-relation.cc
> +++ b/gcc/value-relation.cc
> @@ -1297,8 +1297,9 @@ path_oracle::killing_def (tree ssa)
>        fprintf (dump_file, "\n");
>      }
>  
> +  unsigned v = SSA_NAME_VERSION (ssa);
>    bitmap b = BITMAP_ALLOC (&m_bitmaps);
> -  bitmap_set_bit (b, SSA_NAME_VERSION (ssa));
> +  bitmap_set_bit (b, v);
>    equiv_chain *ptr = (equiv_chain *) obstack_alloc (&m_chain_obstack,
>  						    sizeof (equiv_chain));
>    ptr->m_names = b;
> @@ -1306,6 +1307,24 @@ path_oracle::killing_def (tree ssa)
>    ptr->m_next = m_equiv.m_next;
>    m_equiv.m_next = ptr;
>    bitmap_ior_into (m_equiv.m_names, b);
> +
> +  // Walk the relation list an remove SSA from any relations.

s/an /and /

> +  if (!bitmap_bit_p (m_relations.m_names, v))
> +    return;
> +
> +  bitmap_clear_bit (m_relations.m_names, v);

IIRC bitmap_clear_bit returns true if the bit was set, false otherwise,
so should be used as if(!bitmap_clear_bit) above.
I would not be surprised if this generates better code as we probably
do not grok to optimize the !bit_p else clear_bit combo. Shame (?).

> +  relation_chain **prev = &(m_relations.m_head);

s/[()]//
thanks,

> +  relation_chain *next = NULL;
> +  for (relation_chain *ptr = m_relations.m_head; ptr; ptr = next)
> +    {
> +      gcc_checking_assert (*prev == ptr);
> +      next = ptr->m_next;
> +      if (SSA_NAME_VERSION (ptr->op1 ()) == v
> +	  || SSA_NAME_VERSION (ptr->op2 ()) == v)
> +	*prev = ptr->m_next;
> +      else
> +	prev = &(ptr->m_next);
> +    }
>  }
>  
>  // Register relation K between SSA1 and SSA2, resolving unknowns by
  

Patch

diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index 2acf375ca9a..0ad4f7a9495 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -1297,8 +1297,9 @@  path_oracle::killing_def (tree ssa)
       fprintf (dump_file, "\n");
     }
 
+  unsigned v = SSA_NAME_VERSION (ssa);
   bitmap b = BITMAP_ALLOC (&m_bitmaps);
-  bitmap_set_bit (b, SSA_NAME_VERSION (ssa));
+  bitmap_set_bit (b, v);
   equiv_chain *ptr = (equiv_chain *) obstack_alloc (&m_chain_obstack,
 						    sizeof (equiv_chain));
   ptr->m_names = b;
@@ -1306,6 +1307,24 @@  path_oracle::killing_def (tree ssa)
   ptr->m_next = m_equiv.m_next;
   m_equiv.m_next = ptr;
   bitmap_ior_into (m_equiv.m_names, b);
+
+  // Walk the relation list an remove SSA from any relations.
+  if (!bitmap_bit_p (m_relations.m_names, v))
+    return;
+
+  bitmap_clear_bit (m_relations.m_names, v);
+  relation_chain **prev = &(m_relations.m_head);
+  relation_chain *next = NULL;
+  for (relation_chain *ptr = m_relations.m_head; ptr; ptr = next)
+    {
+      gcc_checking_assert (*prev == ptr);
+      next = ptr->m_next;
+      if (SSA_NAME_VERSION (ptr->op1 ()) == v
+	  || SSA_NAME_VERSION (ptr->op2 ()) == v)
+	*prev = ptr->m_next;
+      else
+	prev = &(ptr->m_next);
+    }
 }
 
 // Register relation K between SSA1 and SSA2, resolving unknowns by