	* tree-ssa-pre.c (alloc_expression_id): Fix use of VEC_reserve.
	* tree-into-ssa.c (get_ssa_name_ann): Likewise.
	(mark_phi_for_rewrite): Likewise.
	(compute_global_livein): Use VEC_reserve outside the innermost
	loop and VEC_quick_push instead of VEC_safe_push in that loop.
	(update_ssa): Re-organize to avoid unnecessary sbitmap_zero'ing
	of new_ssa_names and old_ssa_names.  Allocate phis_to_rewrite to
	the correct initial size.

Index: tree-ssa-pre.c
===================================================================
--- tree-ssa-pre.c	(revision 190267)
+++ tree-ssa-pre.c	(working copy)
@@ -249,7 +249,8 @@ alloc_expression_id (pre_expr expr)
       /* VEC_safe_grow_cleared allocates no headroom.  Avoid frequent
 	 re-allocations by using VEC_reserve upfront.  There is no
 	 VEC_quick_grow_cleared unfortunately.  */
-      VEC_reserve (unsigned, heap, name_to_id, num_ssa_names);
+      unsigned old_len = name_to_id ? VEC_length (unsigned, name_to_id) : 0;
+      VEC_reserve (unsigned, heap, name_to_id, num_ssa_names - old_len);
       VEC_safe_grow_cleared (unsigned, heap, name_to_id, num_ssa_names);
       gcc_assert (VEC_index (unsigned, name_to_id, version) == 0);
       VEC_replace (unsigned, name_to_id, version, expr->id);
Index: tree-into-ssa.c
===================================================================
--- tree-into-ssa.c	(revision 190268)
+++ tree-into-ssa.c	(working copy)
@@ -101,6 +101,9 @@ sbitmap interesting_blocks;
    released after we finish updating the SSA web.  */
 static bitmap names_to_release;
 
+/* VEC of VECs of PHIs to rewrite in a basic block.  Element I corresponds
+   the to basic block with index I.  Allocated once per compilation, *not*
+   released between different functions.  */
 static VEC(gimple_vec, heap) *phis_to_rewrite;
 
 /* The bitmap of non-NULL elements of PHIS_TO_REWRITE.  */
@@ -310,9 +313,11 @@ get_ssa_name_ann (tree name)
 
   if (ver >= len)
     {
+      unsigned old_len = VEC_length (ssa_name_info_p, info_for_ssa_name);
       unsigned new_len = num_ssa_names;
 
-      VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name, new_len);
+      VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name,
+		   new_len - old_len);
       while (len++ < new_len)
 	{
 	  struct ssa_name_info *info = XCNEW (struct ssa_name_info);
@@ -431,6 +436,10 @@ compute_global_livein (bitmap livein, bitmap def_b
       /* Pull a block off the worklist.  */
       basic_block bb = VEC_pop (basic_block, worklist);
 
+      /* Make sure we have at least enough room in the work list
+	 for all predecessors of this block.  */
+      VEC_reserve (basic_block, heap, worklist, EDGE_COUNT (bb->preds));
+
       /* For each predecessor block.  */
       FOR_EACH_EDGE (e, ei, bb->preds)
 	{
@@ -442,7 +451,7 @@ compute_global_livein (bitmap livein, bitmap def_b
 	      && ! bitmap_bit_p (def_blocks, pred_index)
 	      && bitmap_set_bit (livein, pred_index))
 	    {
-	      VEC_safe_push (basic_block, heap, worklist, pred);
+	      VEC_quick_push (basic_block, worklist, pred);
 	    }
 	}
     }
@@ -970,7 +979,7 @@ static void
 mark_phi_for_rewrite (basic_block bb, gimple phi)
 {
   gimple_vec phis;
-  unsigned i, idx = bb->index;
+  unsigned n, idx = bb->index;
 
   if (rewrite_uses_p (phi))
     return;
@@ -981,10 +990,11 @@ mark_phi_for_rewrite (basic_block bb, gimple phi)
     return;
 
   bitmap_set_bit (blocks_with_phis_to_rewrite, idx);
-  VEC_reserve (gimple_vec, heap, phis_to_rewrite, last_basic_block + 1);
-  for (i = VEC_length (gimple_vec, phis_to_rewrite); i <= idx; i++)
-    VEC_quick_push (gimple_vec, phis_to_rewrite, NULL);
 
+  n = (unsigned) last_basic_block + 1;
+  if (VEC_length (gimple_vec, phis_to_rewrite) < n)
+    VEC_safe_grow_cleared (gimple_vec, heap, phis_to_rewrite, n);
+
   phis = VEC_index (gimple_vec, phis_to_rewrite, idx);
   if (!phis)
     phis = VEC_alloc (gimple, heap, 10);
@@ -3146,6 +3156,12 @@ update_ssa (unsigned update_flags)
   sbitmap_iterator sbi;
   tree sym;
 
+  /* Only one update flag should be set.  */
+  gcc_assert (update_flags == TODO_update_ssa
+              || update_flags == TODO_update_ssa_no_phi
+	      || update_flags == TODO_update_ssa_full_phi
+	      || update_flags == TODO_update_ssa_only_virtuals);
+
   if (!need_ssa_update_p (cfun))
     return;
 
@@ -3156,31 +3172,25 @@ update_ssa (unsigned update_flags)
 
   if (!update_ssa_initialized_fn)
     init_update_ssa (cfun);
+  else if (update_flags == TODO_update_ssa_only_virtuals)
+    {
+      /* If we only need to update virtuals, remove all the mappings for
+	 real names before proceeding.  The caller is responsible for
+	 having dealt with the name mappings before calling update_ssa.  */
+      sbitmap_zero (old_ssa_names);
+      sbitmap_zero (new_ssa_names);
+    }
+
   gcc_assert (update_ssa_initialized_fn == cfun);
 
   blocks_with_phis_to_rewrite = BITMAP_ALLOC (NULL);
   if (!phis_to_rewrite)
-    phis_to_rewrite = VEC_alloc (gimple_vec, heap, last_basic_block);
+    phis_to_rewrite = VEC_alloc (gimple_vec, heap, last_basic_block + 1);
   blocks_to_update = BITMAP_ALLOC (NULL);
 
   /* Ensure that the dominance information is up-to-date.  */
   calculate_dominance_info (CDI_DOMINATORS);
 
-  /* Only one update flag should be set.  */
-  gcc_assert (update_flags == TODO_update_ssa
-              || update_flags == TODO_update_ssa_no_phi
-	      || update_flags == TODO_update_ssa_full_phi
-	      || update_flags == TODO_update_ssa_only_virtuals);
-
-  /* If we only need to update virtuals, remove all the mappings for
-     real names before proceeding.  The caller is responsible for
-     having dealt with the name mappings before calling update_ssa.  */
-  if (update_flags == TODO_update_ssa_only_virtuals)
-    {
-      sbitmap_zero (old_ssa_names);
-      sbitmap_zero (new_ssa_names);
-    }
-
   insert_phi_p = (update_flags != TODO_update_ssa_no_phi);
 
   /* If there are names defined in the replacement table, prepare
