[lto] implement awful types_compatible_p hack

Nathan Froyd froydnj@codesourcery.com
Sat Dec 22 19:39:00 GMT 2007


I could spend several pages convincing y'all I know this is a horrible,
awful hack.

Instead, I will state the root issue: we need to merge types across
translation units.  Otherwise--this was the example that broke for
me--we wind up with something like (&foo)->bar from forwprop, which IIUC
is equivalent to (*&foo).bar and GCC is unable to optimize away the *&
because types don't match.  We eventually ICE.  I understand the
incremental compiler inserts VIEW_CONVERT_EXPRs where necessary to avoid
situations like this.

I will fix this.  But not right now; it requires more cycles than I can
spare at the moment.

253.perlbmk now compiles (with -fwrapv) and runs properly.  This leaves
a miscompile of 176.gcc as the only remaining C SPECint benchmark that
LTO doesn't work with.

Committed to the LTO branch.

-Nathan

	* lto-lang.c (lto_types_compatible_p): New function.
	(LANG_HOOKS_TYPES_COMPATIBLE_P): Define.

Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 131119)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -452,6 +452,31 @@ lto_builtin_function (tree decl)
   return decl;
 }
 
+static int
+lto_types_compatible_p (tree type1, tree type2)
+{
+  if (TREE_CODE (type1) == RECORD_TYPE
+      && TREE_CODE (type2) == RECORD_TYPE)
+    {
+      /* Check structural equality.  */
+      tree f1, f2;
+      int success = 1;
+
+      for (f1 = TYPE_FIELDS (type1), f2 = TYPE_FIELDS (type2);
+	   f1 && f2;
+	   f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
+	{
+	  if (TREE_CODE (f1) != TREE_CODE (f2)
+	      || DECL_NAME (f1) != DECL_NAME (f2))
+	    break;
+	}
+
+      return f1 && f2 ? 0 : 1;
+    }
+
+  return TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2);
+}
+
 static void
 lto_register_builtin_type (tree type, const char *name)
 {
@@ -575,6 +600,8 @@ lto_init (void)
 #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
+#undef LANG_HOOKS_TYPES_COMPATIBLE_P
+#define LANG_HOOKS_TYPES_COMPATIBLE_P lto_types_compatible_p
 
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 



More information about the Gcc-patches mailing list