[gcc(refs/users/pheeck/heads/sccp)] fixed bug when scc references same var multiple times

Filip Kastl pheeck@gcc.gnu.org
Mon Sep 5 09:27:48 GMT 2022


https://gcc.gnu.org/g:e92422ecae491dc4655d206e96a6b0536e1eaccf

commit e92422ecae491dc4655d206e96a6b0536e1eaccf
Author: Filip Kastl <filip.kastl@gmail.com>
Date:   Mon Sep 5 11:27:39 2022 +0200

    fixed bug when scc references same var multiple times

Diff:
---
 gcc/sccp.cc | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/sccp.cc b/gcc/sccp.cc
index 4dcedc293fd..1ac4474c019 100644
--- a/gcc/sccp.cc
+++ b/gcc/sccp.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include <iostream>
 #include "gimple-pretty-print.h"
 #include "vec.h"
+#include "hash-set.h"
 #include "libiberty.h"
 
 #include "print-tree.h"
@@ -373,7 +374,7 @@ static void
 process_scc (vec<gphi *> scc)
 {
   vec<gphi *> inner = vNULL;
-  vec<tree> outer_ops = vNULL;
+  hash_set<tree> outer_ops;
 
   for (gphi *phi : scc)
     {
@@ -400,7 +401,7 @@ process_scc (vec<gphi *> scc)
 
 	  if (!op_in_scc)
 	    {
-	      outer_ops.safe_push (op);
+	      outer_ops.add (op);
 	      is_inner = false;
 	    }
 	}
@@ -412,9 +413,19 @@ process_scc (vec<gphi *> scc)
     }
 
   // TODO if == 0 -> unreachable?
-  if (outer_ops.length () == 1)
-    replace_scc_by_value (scc, outer_ops.pop());
-  else if (outer_ops.length () > 1)
+  if (outer_ops.elements () == 1)
+    {
+      /* Get the only operand in outer_ops.  */
+      tree outer_op;
+      for (tree foo : outer_ops)
+	{
+	  outer_op = foo;
+	  break;
+	}
+
+      replace_scc_by_value (scc, outer_op);
+    }
+  else if (outer_ops.elements () > 1)
     {
       remove_redundant_phis (inner);
     }


More information about the Gcc-cvs mailing list