[PATCH][RFC] ARRAY_REF on pointers and more

Chris Lattner clattner@apple.com
Tue May 5 16:31:00 GMT 2009


On May 4, 2009, at 3:57 AM, Richard Guenther wrote:

>
> This patch tries to address the fact that our optimization  
> capabilities
> are weaker for array like accesses through pointers than through real
> array accesses.  The problem and suggestions for solutions came up in
> the past as "array-ref on pointers" or also in the context of  
> designing
> new memory reference trees on the mem-ref branch.

Hi Richard,

This is similar to a problem we have in the llvm-gcc front-end.  My  
solution there was to just hack ARRAY_REF to directly allow a pointer  
as the first operand.  The semantics are that ARRAY_REF(ptr, i) ->  
*(ptr+i) - i.e. that the scale of the index stays implicit.  This  
actually required surprisingly few changes throughout the tree level  
of the compiler to support, but we didn't update tree-ssa or any of  
the RTL stuff to adjust for the change.

With this change, pointer arithmetic can be directly lowered into the  
LLVM getelementptr instruction, which is how LLVM also represents  
array addressing.

-Chris



More information about the Gcc-patches mailing list