diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ad4b63bc675eb73c8d0a630564265ac18075da73..c6cf33c20f2696ffbc0a777e80b619d3521de600 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
 2008-08-13  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* dwarf2out.c (dwarf_stack_op_name): Remove prototype.
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 3799e062b37ecc33e53c34293e49edb0b76df781..2f6af03117e605224955ac77cc5f8bd90463e432 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -2013,7 +2013,7 @@ gimple_call_set_chain (gimple gs, tree chain)
   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);
 }
 
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 336c54ec7004cd68006ed70f85bbefdd1b5f9ef0..9e8ff56495edc253017b35261e199de14b8de4bc 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -2436,7 +2436,7 @@ create_component_ref_by_pieces_1 (basic_block block, vn_reference_t ref,
     {
     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_block block, vn_reference_t ref,
 				   : 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;
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index f6492bdafd830bbf3e27060185e927f54ffa0473..f502440b46fb7d44858acffd1d0533ad4ad905ad 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -686,12 +686,12 @@ copy_reference_ops_from_call (gimple call,
   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 call,
       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