Index: gcc/cse.c
===================================================================
--- gcc/cse.c	(revision 160724)
+++ gcc/cse.c	(working copy)
@@ -5989,6 +5989,7 @@ cse_process_notes_1 (rtx x, rtx object,
   enum rtx_code code = GET_CODE (x);
   const char *fmt = GET_RTX_FORMAT (code);
   int i;
+  bool did_change = false;
 
   switch (code)
     {
@@ -6057,7 +6058,18 @@ cse_process_notes_1 (rtx x, rtx object,
   for (i = 0; i < GET_RTX_LENGTH (code); i++)
     if (fmt[i] == 'e')
       validate_change (object, &XEXP (x, i),
-		       cse_process_notes (XEXP (x, i), object, changed), 0);
+		       cse_process_notes (XEXP (x, i), object, &did_change), 0);
+
+  /* We may need to rebuild the expression after substitution.
+     e.g. if the first operand of a PLUS is replaced by a constant.  */
+  if (did_change)
+    {
+      rtx simplified;
+      *changed = true;
+      simplified = simplify_rtx(x);
+      if (simplified)
+	x = simplified;
+    }
 
   return x;
 }
