This patch adds an inchash hasher for wide_int-based types.
It means that hash_tree no longer hashes TREE_INT_CST_EXT_NUNITS,
but that was redundant with hashing the type.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
OK to install?

Richard


2017-10-13  Richard Sandiford  <richard.sandif...@linaro.org>

gcc/
        * inchash.h (inchash::hash::add_wide_int): New function.
        * lto-streamer-out.c (hash_tree): Use it.

Index: gcc/inchash.h
===================================================================
--- gcc/inchash.h       2017-10-13 14:59:35.120146199 +0100
+++ gcc/inchash.h       2017-10-13 15:00:00.743308010 +0100
@@ -63,6 +63,15 @@ hashval_t iterative_hash_hashval_t (hash
     val = iterative_hash_host_wide_int (v, val);
   }
 
+  /* Add wide_int-based value V.  */
+  template<typename T>
+  void add_wide_int (const generic_wide_int<T> &x)
+  {
+    add_int (x.get_len ());
+    for (unsigned i = 0; i < x.get_len (); i++)
+      add_hwi (x.elt (i));
+  }
+
   /* Hash in pointer PTR.  */
   void add_ptr (const void *ptr)
   {
Index: gcc/lto-streamer-out.c
===================================================================
--- gcc/lto-streamer-out.c      2017-10-13 14:59:35.121978207 +0100
+++ gcc/lto-streamer-out.c      2017-10-13 15:00:00.743308010 +0100
@@ -1028,13 +1028,7 @@ #define visit(SIBLING) \
   hstate.commit_flag ();
 
   if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
-    {
-      int i;
-      hstate.add_hwi (TREE_INT_CST_NUNITS (t));
-      hstate.add_hwi (TREE_INT_CST_EXT_NUNITS (t));
-      for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
-       hstate.add_hwi (TREE_INT_CST_ELT (t, i));
-    }
+    hstate.add_wide_int (wi::to_widest (t));
 
   if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
     {

Reply via email to