Patchwork argument of alloca in terms of units or not

login
register
mail settings
Submitter Tom de Vries
Date Sept. 29, 2011, 3:57 p.m.
Message ID <4E849556.5010901@mentor.com>
Download mbox | patch
Permalink /patch/116979/
State New
Headers show

Comments

Tom de Vries - Sept. 29, 2011, 3:57 p.m.
Richard,

in gimplify_vla_decl, the alloca argument seems to be the size of the vla in units:
...
  t = build_call_expr (t, 1, DECL_SIZE_UNIT (decl));
...

I wonder why we are going through this 8 vs. BITS_PER_UNIT conversion here:
...
  elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1);
  n_elem = size * 8 / BITS_PER_UNIT;
  align = MIN (size * 8, BIGGEST_ALIGNMENT);
...
The element size is BITS_PER_UNIT, so 1 unit, and size is in units.

Shouldn't this be:
...
...

Thanks,
- Tom
Richard Guenther - Sept. 30, 2011, 8:08 a.m.
On Thu, Sep 29, 2011 at 5:57 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> Richard,
>
> in gimplify_vla_decl, the alloca argument seems to be the size of the vla in units:
> ...
>  t = build_call_expr (t, 1, DECL_SIZE_UNIT (decl));
> ...
>
> I wonder why we are going through this 8 vs. BITS_PER_UNIT conversion here:
> ...
>  elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1);
>  n_elem = size * 8 / BITS_PER_UNIT;
>  align = MIN (size * 8, BIGGEST_ALIGNMENT);
> ...
> The element size is BITS_PER_UNIT, so 1 unit, and size is in units.

No, the size is in bytes and the gimplify code lacks the conversion.

Richard.

>
> Shouldn't this be:
> ...
> Index: tree-ssa-ccp.c
> ===================================================================
> --- tree-ssa-ccp.c (revision 179210)
> +++ tree-ssa-ccp.c (working copy)
> @@ -1722,8 +1722,8 @@ fold_builtin_alloca_for_var (gimple stmt
>
>   /* Declare array.  */
>   elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1);
> -  n_elem = size * 8 / BITS_PER_UNIT;
> -  align = MIN (size * 8, BIGGEST_ALIGNMENT);
> +  n_elem = size;
> +  align = MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT);
>   if (align < BITS_PER_UNIT)
>     align = BITS_PER_UNIT;
>   array_type = build_array_type_nelts (elem_type, n_elem);
> ...
>
> Thanks,
> - Tom
>

Patch

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c (revision 179210)
+++ tree-ssa-ccp.c (working copy)
@@ -1722,8 +1722,8 @@  fold_builtin_alloca_for_var (gimple stmt

   /* Declare array.  */
   elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1);
-  n_elem = size * 8 / BITS_PER_UNIT;
-  align = MIN (size * 8, BIGGEST_ALIGNMENT);
+  n_elem = size;
+  align = MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT);
   if (align < BITS_PER_UNIT)
     align = BITS_PER_UNIT;
   array_type = build_array_type_nelts (elem_type, n_elem);