I am writing a "quick and dirty" DCE pass which is faster the current DCE and does not do anything with stores/loads. It passes over all the live SSA_NAMEs by looping over ssa_name. But I am running into places where SSA_NAMEs not released when they become dead. I have a fix for some of these places, we
call bsi_remove and don't call release_defs (I will submit those later,
I already tested it last night) but there are still other places where the
SSA_NAME becomes not alive but does not get released.
On example is:
int f(void)
{
  int i;
  int *j = &i;
  i = 1;
  return *j;
}

With the attached patch, I get the following error:
t1.c: In function 'f':
t1.c:2: error: SSA_NAME_DEF_STMT does not define the correct SSA_NAME
while verifying SSA_NAME i_3 in statement
i_1 = 1;

i_3 no longer exists (can be seen by looking at the tree dumps
and at the BasicBlock at the time of checking) but it has not been released so it is still in the ssa_name VEC and refers to the "i_1 = 1;" statement.
If we take this after DCE, we still refer to a statement which no longer
exists which we don't collect in the GC.

Could someone look into this and see what they can do? This will improve
memory usage in GCC and also there will be more SSA_NAME reuse which is
good.

Thanks,
Andrew Pinsk




Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.106
diff -u -p -r2.106 tree-ssa.c
--- tree-ssa.c  19 Jul 2005 20:20:40 -0000      2.106
+++ tree-ssa.c  24 Aug 2005 21:23:51 -0000
@@ -184,6 +184,27 @@ verify_def (basic_block bb, basic_block 
       print_generic_stmt (stderr, stmt, TDF_VOPS);
       goto err;
     }
+  
+  if (!is_virtual)
+    {
+      if (TREE_CODE (stmt) == RETURN_EXPR)
+        stmt = TREE_OPERAND (stmt, 0);
+      if (TREE_CODE (stmt) != MODIFY_EXPR && TREE_CODE (stmt) != PHI_NODE)
+        {
+         error ("SSA_NAME_DEF_STMT is not a MODIFY_EXPR or a PHI_NODE");
+         goto err;
+       }
+      if (TREE_CODE (stmt) == MODIFY_EXPR && TREE_OPERAND (stmt, 0) != 
ssa_name)
+        {
+         error ("SSA_NAME_DEF_STMT does not define the correct SSA_NAME");
+         goto err;
+       }
+      if (TREE_CODE (stmt) == PHI_NODE && PHI_RESULT_TREE (stmt) != ssa_name)
+        {
+         error ("SSA_NAME_DEF_STMT does not define the correct SSA_NAME");
+         goto err;
+       }
+    }
 
   return false;
 
@@ -659,8 +680,9 @@ verify_ssa (bool check_modified_stmt)
          if (!IS_EMPTY_STMT (stmt))
            {
              basic_block bb = bb_for_stmt (stmt);
-             verify_def (bb, definition_block,
-                         name, stmt, !is_gimple_reg (name));
+             if (verify_def (bb, definition_block,
+                             name, stmt, !is_gimple_reg (name)))
+               goto err;
 
            }
        }
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.216
diff -u -p -r2.216 tree-cfg.c
--- tree-cfg.c  13 Aug 2005 17:28:36 -0000      2.216
+++ tree-cfg.c  24 Aug 2005 21:23:52 -0000
@@ -3140,6 +3140,21 @@ verify_expr (tree *tp, int *walk_subtree
          error ("GIMPLE register modified with BIT_FIELD_REF");
          return t;
        }
+      if (TREE_CODE (x) == SSA_NAME)
+        {
+         tree t1 = SSA_NAME_DEF_STMT (x);
+         if (TREE_CODE (t1) == RETURN_EXPR)
+           t1 = TREE_OPERAND (t1, 0);
+         if (t1 != t)
+           {
+             fprintf (stderr, "SSA_NAME ");
+             print_generic_expr (stderr, x, 0);
+             fprintf (stderr, "points to the wrong statement\n");
+             print_generic_stmt (stderr, SSA_NAME_DEF_STMT (x), TDF_VOPS);
+             print_generic_stmt (stderr, t, TDF_VOPS);
+             return t;
+           }
+       }
       break;
 
     case ADDR_EXPR:

Reply via email to