This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] CONSTANT_ALIGNMENT is missed in builtins.c


Hi Adam,

On Thu, 31 Aug 2006, Adam Nemet wrote:
> 	* tree.h (extract_array_ref): Declare it.
> 	* fold-const.c (extract_array_ref): Export it.
> 	* builtins.c (get_pointer_alignment): Use extract_array_ref to
> 	handle ARRAY_REFs.

This patch is not bad, but I wonder whether its possible to implement
this without requiring calls to fold_buildN; ideally it should be possible
to determine pointer alignment without having to allocate temporary trees.

> +  /* Lower ARRAY_REFs into pointer arithmetic.  */
> +  if (extract_array_ref (exp, &base, &offset))
> +    {
> +      /* extract_array_ref strips ADDR_EXPR in front of ARRAY_TYPEs.  */
> +      if (TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE)
> +	base = fold_build1 (ADDR_EXPR, TREE_TYPE (exp), base);
> +
> +      if (offset)
> +	base = fold_build2 (PLUS_EXPR, TREE_TYPE (exp), base, offset);
> +      exp = base;
> +    }
> +

Perhaps if the code for handling ADDR_EXPR was split out of the switch
into its own "get_addr_alignment", it could be shared here without
having to build a new ADDR_EXPR node.  Likewise, the PLUS_EXPR
handling logic could also be duplicated.

I'm just trying to get all of the nice benefits of your change
without the memory overhead of these additional nodes.  Given an
expression such as "a[b]", you'll allocate a new ADDR_EXPR node
and a new PLUS_EXPR node, only to immediately throw them away
as soon as we discover !host_integerp(offset).


If avoiding memory leakage ends up being too invasive, we can always
approve this version of your patch.  But I'm keen for commonly used
infrastructure (and potentially widely useful infrastructure) to avoid
allocating/wasting memory if at all possible.

I hope this sounds reasonable.  Thanks in advance,

Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]