public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/112444 - avoid bougs PHI value-numbering
@ 2023-11-09 10:50 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-09 10:50 UTC (permalink / raw)
  To: gcc-patches

With .DEFERRED_INIT ssa_undefined_value_p () can return true for
values we did not visit (because they proved unreachable) but
are not .VN_TOP.  Avoid using those as value which, because they
are not visited, are assumed to be defined outside of the region.

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

	PR tree-optimization/112444
	* tree-ssa-sccvn.cc (visit_phi): Avoid using not visited
	defs as undefined vals.

	* gcc.dg/torture/pr112444.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr112444.c | 65 +++++++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   | 16 +++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr112444.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr112444.c b/gcc/testsuite/gcc.dg/torture/pr112444.c
new file mode 100644
index 00000000000..61c7ec9b22e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr112444.c
@@ -0,0 +1,65 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+int qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset,
+    qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset,
+    qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error,
+    qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i;
+
+int g_string_new(), g_string_append_len(), qmi_message_tlv_read_guint8();
+
+void qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message() {
+  int printable = g_string_new();
+  for (;;) {
+    {
+      if (__builtin_expect(({
+                             int _g_boolean_var_4;
+                             if (printable)
+                               _g_boolean_var_4 = 1;
+                             else
+                               _g_boolean_var_4 = 0;
+                             _g_boolean_var_4;
+                           }),
+                           0))
+        g_string_append_len();
+    }
+    unsigned char tmp;
+    qmi_message_tlv_read_guint8(
+        qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset,
+        qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset,
+        tmp,
+        qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error);
+    {
+      {
+        if (__builtin_expect(({
+                               int _g_boolean_var_4;
+                               if (printable)
+                                 _g_boolean_var_4 = 1;
+                               else
+                                 _g_boolean_var_4 = 0;
+                               _g_boolean_var_4;
+                             }),
+                             0))
+          g_string_append_len();
+      }
+    }
+    for (
+        ;
+        qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i;) {
+      unsigned char tmp;
+      qmi_message_tlv_read_guint8(&tmp);
+      {
+        if (__builtin_expect(({
+                               int _g_boolean_var_4;
+                               if (printable)
+                                 _g_boolean_var_4 = 1;
+                               else
+                                 _g_boolean_var_4 = 0;
+                               _g_boolean_var_4;
+                             }),
+                             0))
+          g_string_append_len();
+      }
+    }
+  }
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0b2c10dcc1a..11537fa3e0b 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5911,6 +5911,7 @@ static bool
 visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 {
   tree result, sameval = VN_TOP, seen_undef = NULL_TREE;
+  bool seen_undef_visited = false;
   tree backedge_val = NULL_TREE;
   bool seen_non_backedge = false;
   tree sameval_base = NULL_TREE;
@@ -5941,10 +5942,12 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 	if (def == PHI_RESULT (phi))
 	  continue;
 	++n_executable;
+	bool visited = true;
 	if (TREE_CODE (def) == SSA_NAME)
 	  {
+	    tree val = SSA_VAL (def, &visited);
 	    if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
-	      def = SSA_VAL (def);
+	      def = val;
 	    if (e->flags & EDGE_DFS_BACK)
 	      backedge_val = def;
 	  }
@@ -5956,7 +5959,16 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 	else if (TREE_CODE (def) == SSA_NAME
 		 && ! virtual_operand_p (def)
 		 && ssa_undefined_value_p (def, false))
-	  seen_undef = def;
+	  {
+	    if (!seen_undef
+		/* Avoid having not visited undefined defs if we also have
+		   a visited one.  */
+		|| (!seen_undef_visited && visited))
+	      {
+		seen_undef = def;
+		seen_undef_visited = visited;
+	      }
+	  }
 	else if (sameval == VN_TOP)
 	  {
 	    sameval = def;
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-09 10:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 10:50 [PATCH] tree-optimization/112444 - avoid bougs PHI value-numbering Richard Biener

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).