This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[vta,trunk?] stabilize hashing of SSA names and builtin function DECLs


I ran into this debugging an -fcompare-debug failure that turned out
to be a heisenbug.  The box had virtual address space randomization
turned on, and that was what made it a heisenbug.

I don't recall which pass it was that would vary the traverse order in
a hash table because of varying hash numbers, computed out of
randomized pointers, but this is not important.  (My faulty memory
tells me it was SCCVN, but I don't see any htab_traverse in there).

Pointers don't belong in hashes that could affect traversal order in a
way that might change the generated code.  We don't want the compiler
issuing different code just because we recompile.  This could even
break bootstrap!

Turns out it's quite simple to just not use pointers in generic hashes
at all, and use UIDs instead.  This is what this patch does, fixing
that heisenbug for good.

Here's the patch that I'm checking in.  It's the last one I have for
this series.  The branch builds just fine again on x86_64.  There are
still some Ada regressions on i686, and a few compare-debug failures
here and there that I'm looking into.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* tree.c (iterative_hash_pointer): Delete.
	(iterative_hash_expr): Short-circuit handling of NULL pointer.
	Hash UIDs and versions of SSA names.  Don't special-case built-in
	function declarations.

Index: gcc/tree.c
===================================================================
--- gcc/tree.c.orig	2008-10-16 01:21:38.000000000 -0300
+++ gcc/tree.c	2008-10-16 01:27:02.000000000 -0300
@@ -3630,24 +3630,6 @@ iterative_hash_hashval_t (hashval_t val,
   return val2;
 }
 
-/* Produce good hash value combining PTR and VAL2.  */
-static inline hashval_t
-iterative_hash_pointer (const void *ptr, hashval_t val2)
-{
-  if (sizeof (ptr) == sizeof (hashval_t))
-    return iterative_hash_hashval_t ((size_t) ptr, val2);
-  else
-    {
-      hashval_t a = (hashval_t) (size_t) ptr;
-      /* Avoid warnings about shifting of more than the width of the type on
-         hosts that won't execute this path.  */
-      int zero = 0;
-      hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
-      mix (a, b, val2);
-      return val2;
-    }
-}
-
 /* Produce good hash value combining VAL and VAL2.  */
 static inline hashval_t
 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
@@ -5306,7 +5288,7 @@ iterative_hash_expr (const_tree t, hashv
   char tclass;
 
   if (t == NULL_TREE)
-    return iterative_hash_pointer (t, val);
+    return iterative_hash_hashval_t (0, val);
 
   code = TREE_CODE (t);
 
@@ -5340,7 +5322,9 @@ iterative_hash_expr (const_tree t, hashv
 
     case SSA_NAME:
       /* we can just compare by pointer.  */
-      return iterative_hash_pointer (t, val);
+      val = iterative_hash_host_wide_int (DECL_UID (SSA_NAME_VAR (t)), val);
+      val = iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val);
+      return val;
 
     case TREE_LIST:
       /* A list of expressions, for a CALL_EXPR or as the elements of a
@@ -5366,11 +5350,10 @@ iterative_hash_expr (const_tree t, hashv
 	 hash codes.  */
       if (DECL_BUILT_IN (t))
 	{
-	  val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)], 
-				      val);
-	  return val;
+	  t = built_in_decls[DECL_FUNCTION_CODE (t)];
+	  code = TREE_CODE (t);
 	}
-      /* else FALL THROUGH */
+      /* FALL THROUGH */
     default:
       tclass = TREE_CODE_CLASS (code);
 
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member       ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]