diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9ee830911280a65a5dc2e64e1b0dbe18ad8f18e2..f9eea06b60af13d40d288dc4aa87469aa01f12bc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2010-10-18  Bernd Schmidt  <bernds@codesourcery.com>
+
+	PR rtl-optimization/45966
+	* combine.c (try_combine): If added_sets_2, deal with the case
+	where i0 feeds i1 and i1 feeds i2.
+
 2010-10-18  Jan Hubicka  <jh@suse.cz>
 
 	* ipa.c (cgraph_externally_visible_p): Handle externally visible and
diff --git a/gcc/combine.c b/gcc/combine.c
index a5088b0f72bcf974c3c8f84ffe84be3742f77ef8..556228f77b8e14796e67920e2636617bc414d9d9 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -3192,6 +3192,8 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx i0, int *new_direct_jump_p)
 	    t = subst (t, i0dest, i0src, 0, 0);
 	  if (i1_feeds_i2_n)
 	    t = subst (t, i1dest, i1src, 0, 0);
+	  if (i0_feeds_i1_n && i1_feeds_i2_n)
+	    t = subst (t, i0dest, i0src, 0, 0);
 
 	  XVECEXP (newpat, 0, --total_sets) = t;
 	}