public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Improve hashing of decls in ipa-icf-gimple
@ 2020-11-20 19:37 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2020-11-20 19:37 UTC (permalink / raw)
  To: gcc-patches

Hi,
another remaining case is that we end up comparing calls with mismatching
number of parameters or with different permutations of them.

This is because we hash decls to nothing. This patch improves that by
hashing decls by their code and parm decls by indexes that are stable.
Also for defualt defs in SSA_NAMEs we can add the corresponding decl (that
is usually parm decls).

Still we could improve on this by hasing ssa names by their definit parameters
and possibly making maps of other decls and assigning them stable function
local IDs.

Bootstrapped/regtested x86_64-linux, comitted.

	* ipa-icf-gimple.c (func_checker::hash_operand): Improve hashing of
	decls.
diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 250f02391db..7e2b3c4624c 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -229,13 +242,29 @@ func_checker::hash_operand (const_tree arg, inchash::hash &hstate,
 
   switch (TREE_CODE (arg))
     {
+    case PARM_DECL:
+      {
+	unsigned int index = 0;
+	if (DECL_CONTEXT (arg))
+	  for (tree p = DECL_ARGUMENTS (DECL_CONTEXT (arg));
+	       p && index < 32; p = DECL_CHAIN (p), index++)
+	    if (p == arg)
+	      break;
+	hstate.add_int (PARM_DECL);
+	hstate.add_int (index);
+      }
+      return;
     case FUNCTION_DECL:
     case VAR_DECL:
     case LABEL_DECL:
-    case PARM_DECL:
     case RESULT_DECL:
     case CONST_DECL:
+      hstate.add_int (TREE_CODE (arg));
+      return;
     case SSA_NAME:
+      hstate.add_int (SSA_NAME);
+      if (SSA_NAME_IS_DEFAULT_DEF (arg))
+	hash_operand (SSA_NAME_VAR (arg), hstate, flags);
       return;
     case FIELD_DECL:
       inchash::add_expr (DECL_FIELD_OFFSET (arg), hstate, flags);
@@ -252,6 +281,8 @@ func_checker::hash_operand (const_tree arg, inchash::hash &hstate,
       hstate.add_int (0xc10bbe5);
       return;
     }
+  gcc_assert (!DECL_P (arg));
+  gcc_assert (!TYPE_P (arg));
 
   return operand_compare::hash_operand (arg, hstate, flags);
 }

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

only message in thread, other threads:[~2020-11-20 19:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 19:37 Improve hashing of decls in ipa-icf-gimple Jan Hubicka

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