Patchwork Fix a couple of VEC_reserve uses, speed up update_ssa a bit

login
register
mail settings
Submitter Steven Bosscher
Date Aug. 9, 2012, 10:20 p.m.
Message ID <CABu31nNJUURw4Jr92aeGRvwwJjJwePgg1MOgzy4k6WEXxtOMbg@mail.gmail.com>
Download mbox | patch
Permalink /patch/176294/
State New
Headers show

Comments

Steven Bosscher - Aug. 9, 2012, 10:20 p.m.
On Fri, Aug 10, 2012 at 12:15 AM, Richard Henderson <rth@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:
Richard Guenther - Aug. 10, 2012, 9:07 a.m.
On Fri, Aug 10, 2012 at 12:20 AM, Steven Bosscher <stevenb.gcc@gmail.com> wrote:
> On Fri, Aug 10, 2012 at 12:15 AM, Richard Henderson <rth@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

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);