[LLVMdev] Address calculation

Chris Lattner clattner at apple.com
Mon Oct 6 10:24:24 PDT 2008

On Oct 6, 2008, at 9:03 AM, Villmow, Micah wrote:

> I am attempting to get indexing code generation working with my  
> backend. However, it seems that the addresses being calculated is  
> being multiplied by the width of the data type.
> define void @ test_input_index_constant_int(i32 addrspace(11)*  
> %input, i32 addrspace(11)* %result) {
> entry:
>         %input.addr = alloca i32 addrspace(11)*         ; <i32  
> addrspace(11)**> [#uses=2]
>         %result.addr = alloca i32 addrspace(11)*                ;  
> <i32 addrspace(11)**> [#uses=2]
>         store i32 addrspace(11)* %input, i32 addrspace(11)**  
> %input.addr
>         store i32 addrspace(11)* %result, i32 addrspace(11)**  
> %result.addr
>         %tmp = load i32 addrspace(11)** %result.addr            ;  
> <i32 addrspace(11)*> [#uses=1]
>         %tmp1 = load i32 addrspace(11)** %input.addr            ;  
> <i32 addrspace(11)*> [#uses=1]
>         %arrayidx = getelementptr i32 addrspace(11)* %tmp1, i32  
> 23              ; <i32 addrspace(11)*> [#uses=1]
>         %tmp2 = load i32 addrspace(11)* %arrayidx               ;  
> <i32> [#uses=1]
>         store i32 %tmp2, i32 addrspace(11)* %tmp
>         ret void
> }
> The value 23 in the getelementptr is being multiplied by 4 bytes and  
> the generated code is the value 96. However, I don’t want this  
> multiplication to occur and I cannot figure out how to divide the  
> immediate by 4 when lowering the Add instruction that is linked to  
> a  load/store operation.
> So my question is, how do I modified a immediate constant value from  
> an SDValue struct? If that is not possible, what section of code do  
> I need to modify to get LLVM to stop multiplying the index by the  
> data size.

Hi Micah,

You really don't want to change the semantics of the getelementptr  
instruction.  Instead, you should change whatever is generating this  
instruction to generate the appropriate code.  If you want to do an  
offset in terms of bytes, the standard way to do it is to bitcast your  
pointer to "i8*" and then do a getelementptr from that pointer,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081006/c854569d/attachment.html>

More information about the llvm-dev mailing list