Re: [patch] Fix a couple of VEC_reserve uses, speed up update_ssa a bit

2012-08-10 Thread Richard Guenther
On Fri, Aug 10, 2012 at 12:20 AM, Steven Bosscher stevenb@gmail.com wrote:
 On Fri, Aug 10, 2012 at 12:15 AM, Richard Henderson r...@redhat.com wrote:
 On 08/09/2012 03:06 PM, Steven Bosscher wrote:
 +  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_length already handles NULL input.

 I didn't know that. Consider that hunk changed to this:

 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 = VEC_length (unsigned, name_to_id);
 +  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);

Ok with that change.

Thanks,
Richard.


[patch] Fix a couple of VEC_reserve uses, speed up update_ssa a bit

2012-08-09 Thread Steven Bosscher
Hello,

VEC_reserve allocates an *extra* number of slots. There is
unfortunately no VEC_resize op (one of the first things to add after
the merge of the cxx branch, I suppose...), so to grow a VEC without
increasing the used slots count (the VEC_length) it's necessary to
compute the number of extra slots needed and reserve only that number
of slots.

So something like:

  VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name, num_ssa_names);

on an existing VEC with non-null length is wrong. In the worst case,
the VEC_length is already num_ssa_names and the VEC ends up twice as
large as necessary.

Another thing I noticed, is that in update_ssa() we're
sbitmap_zero'ing new_ssa_names and old_ssa_names even after we've
already done so in init_update_ssa. This might seem like a
micro-optimization, but it cuts the time spent in the timevar tree
SSA incremental in half for the test case of PR54146...

Bootstrappedtested on powerpc64-unknown-linux-gnu. OK for trunk?

Ciao!
Steven


vec_reserve.diff
Description: Binary data


Re: [patch] Fix a couple of VEC_reserve uses, speed up update_ssa a bit

2012-08-09 Thread Richard Henderson
On 08/09/2012 03:06 PM, Steven Bosscher wrote:
 +  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_length already handles NULL input.


r~


Re: [patch] Fix a couple of VEC_reserve uses, speed up update_ssa a bit

2012-08-09 Thread Steven Bosscher
On Fri, Aug 10, 2012 at 12:15 AM, Richard Henderson r...@redhat.com wrote:
 On 08/09/2012 03:06 PM, Steven Bosscher wrote:
 +  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_length already handles NULL input.

I didn't know that. Consider that hunk changed to this:

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 = VEC_length (unsigned, name_to_id);
+  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);