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]

Fix bug in PRE


This is another fallout of the recent PRE rewrite: static chains of calls are 
not rematerialized by the new code (they were by the old code).  This causes 
the compiler to be itself miscompiled on i586 and x86-64 with some upcoming 
changes.

Fixed by reinstating and adapting the old code.  Bootstrapped/regtested on 
i585-suse-linux (with a workaround for PR target/37094) and applied on the 
mainline as obvious.


2008-08-13  Eric Botcazou  <ebotcazou@adacore.com>

	* gimple.h (gimple_call_set_chain): Accept SSA variables.
	* tree-ssa-pre.c (create_component_ref_by_pieces_1) <CALL_EXPR>:
	Rematerialize the static chain, if any.
	* tree-ssa-sccvn.c (copy_reference_ops_from_call): Also copy the
	static chain.


-- 
Eric Botcazou
Index: gimple.h
===================================================================
--- gimple.h	(revision 138957)
+++ gimple.h	(working copy)
@@ -2013,7 +2013,7 @@ gimple_call_set_chain (gimple gs, tree c
   GIMPLE_CHECK (gs, GIMPLE_CALL);
   gcc_assert (chain == NULL
               || TREE_CODE (chain) == ADDR_EXPR
-              || DECL_P (chain));
+              || SSA_VAR_P (chain));
   gimple_set_op (gs, 2, chain);
 }
 
Index: tree-ssa-pre.c
===================================================================
--- tree-ssa-pre.c	(revision 138957)
+++ tree-ssa-pre.c	(working copy)
@@ -2436,7 +2436,7 @@ create_component_ref_by_pieces_1 (basic_
     {
     case CALL_EXPR:
       {
-	tree folded;
+	tree folded, sc = currop->op1;
 	unsigned int nargs = 0;
 	tree *args = XNEWVEC (tree, VEC_length (vn_reference_op_s,
 						ref->operands) - 1);
@@ -2453,6 +2453,14 @@ create_component_ref_by_pieces_1 (basic_
 				   : currop->op0,
 				   nargs, args);
 	free (args);
+	if (sc)
+	  {
+	    pre_expr scexpr = get_or_alloc_expr_for (sc);
+	    sc = find_or_generate_expression (block, scexpr, stmts, domstmt);
+	    if (!sc)
+	      return NULL_TREE;
+	    CALL_EXPR_STATIC_CHAIN (folded) = sc;
+	  }
 	return folded;
       }
       break;
Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c	(revision 138957)
+++ tree-ssa-sccvn.c	(working copy)
@@ -686,12 +686,12 @@ copy_reference_ops_from_call (gimple cal
   vn_reference_op_s temp;
   unsigned i;
 
-  /* Copy the call_expr opcode, type, function being called, and
-     arguments.  */
+  /* Copy the type, opcode, function being called and static chain.  */
   memset (&temp, 0, sizeof (temp));
   temp.type = gimple_call_return_type (call);
   temp.opcode = CALL_EXPR;
   temp.op0 = gimple_call_fn (call);
+  temp.op1 = gimple_call_chain (call);
   VEC_safe_push (vn_reference_op_s, heap, *result, &temp);
 
   /* Copy the call arguments.  As they can be references as well,
@@ -701,7 +701,6 @@ copy_reference_ops_from_call (gimple cal
       tree callarg = gimple_call_arg (call, i);
       copy_reference_ops_from_ref (callarg, result);
     }
-  return;
 }
 
 /* Create a vector of vn_reference_op_s structures from REF, a

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