[llvm-dev] Automatically scaled offset Load/stores for arrays

Dilan Manatunga via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 6 10:36:19 PDT 2016


Hi,

I have a question on how I would support load/store instructions where the
offset is automatically scaled by the type. Simply put, any array index
would be scaled by the width, so that there no longer needs to be a
separate

int32_t arr = {...}
for (int i = 0; i < 100. i++) {
   x += arr[i]
}

the llvm code of (code below approximation of what would showup)
%a = ld i32 %arr_ptr, %offset
%x = add i32 %x %a
%offset = offset + 4
%i = %i + 1
%cond  = icmp %i 100 ICMP_ULT
br for.body

would lower to:

%a = ld i32 %arr_ptr, %i
%x = add i32 %x %a
%i = %i + 1
%cond  = icmp %i 100 ICMP_ULT
br for.body

Right now, the only idea I would have is to replace getelementptr
instructions with an intrinsic that computes the offset and pass that in to
the load instruction, and in instruction selection look for patterns of
loads with intrinsic, and convert that to a scaled_arr load.

Sorry if what I am asking is somewhat confusing.
-Dilan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160706/211be971/attachment.html>


More information about the llvm-dev mailing list