Index: tree-ssa-loop-niter.c
===================================================================
--- tree-ssa-loop-niter.c	(revision 192632)
+++ tree-ssa-loop-niter.c	(working copy)
@@ -2506,13 +2506,20 @@ record_niter_bound (struct loop *loop, d
     {
       loop->any_upper_bound = true;
       loop->nb_iterations_upper_bound = i_bound;
+      if (loop->any_estimate
+	  && i_bound.ult (loop->nb_iterations_estimate))
+        loop->nb_iterations_estimate = i_bound;
     }
   if (realistic
       && (!loop->any_estimate
 	  || i_bound.ult (loop->nb_iterations_estimate)))
     {
       loop->any_estimate = true;
-      loop->nb_iterations_estimate = i_bound;
+      if (loop->nb_iterations_upper_bound.ult (i_bound)
+	   && loop->any_upper_bound)
+        loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
+      else
+        loop->nb_iterations_estimate = i_bound;
     }
 
   /* If an upper bound is smaller than the realistic estimate of the
