diff mbox series

tree-optimization/113693 - LC SSA and region VN

Message ID 20240201101140.B12C638582B8@sourceware.org
State New
Headers show
Series tree-optimization/113693 - LC SSA and region VN | expand

Commit Message

Richard Biener Feb. 1, 2024, 10:11 a.m. UTC
The following fixes LC SSA preserving with region VN which was broken
when availability checking was enhanced to treat not visited value
numbers as available.  The following makes sure to honor availability
data we put in place for LC SSA preserving instead.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/113693
	* tree-ssa-sccvn.cc (rpo_elim::eliminate_avail): Honor avail
	data when available.

	* gcc.dg/pr113693.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr113693.c | 13 +++++++++++++
 gcc/tree-ssa-sccvn.cc           | 11 +++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr113693.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/pr113693.c b/gcc/testsuite/gcc.dg/pr113693.c
new file mode 100644
index 00000000000..a6f55199d0f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113693.c
@@ -0,0 +1,13 @@ 
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2 -fdbg-cnt=vect_loop:1" } */
+
+_BitInt(837) g, h;
+
+void
+fn1(void)
+{
+  for (; g; g++)
+    for (; h; h++)
+      ;
+}
+/* { dg-message "dbgcnt" "" { target *-*-* } 0 } */
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 9bed9b3cc69..bbcf86588f9 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7723,12 +7723,15 @@  rpo_elim::eliminate_avail (basic_block bb, tree op)
       if (SSA_NAME_IS_DEFAULT_DEF (valnum))
 	return valnum;
       vn_ssa_aux_t valnum_info = VN_INFO (valnum);
-      /* See above.  */
-      if (!valnum_info->visited)
-	return valnum;
       vn_avail *av = valnum_info->avail;
       if (!av)
-	return NULL_TREE;
+	{
+	  /* See above.  But when there's availability info prefer
+	     what we recorded there for example to preserve LC SSA.  */
+	  if (!valnum_info->visited)
+	    return valnum;
+	  return NULL_TREE;
+	}
       if (av->location == bb->index)
 	/* On tramp3d 90% of the cases are here.  */
 	return ssa_name (av->leader);