[LLVMdev] compare two GEP instructions operand by operand

Eli Friedman
Tue, 30 Aug 2011 15:33:58 -0000

On Tue, Aug 30, 2011 at 8:10 AM, Jimborean Alexandra
<xinfinity_a at yahoo.com> wrote:
> Hi,
> I have a question regarding the GEP instruction. Is it correct to consider
> that two GEP instructions compute the same memory address if and only if
all
> their corresponding fields are equal?
>
> For instance, for a two-dimensional array of integers, can we have two GEP
> instructions that are equal?
>
>   %arrayidx = getelementptr [10 x [30 x i32]]* @main.B, i64 0, i64 0, i64
> %tmp157
>   %tmp = load i32* getelementptr inbounds ([10 x [30 x i32]]* @main.B, i64
> 0, i64 3, i64 10), align 8
> although their corresponding indices are different? For instance if %tmp157
> goes out of the bounds of the line 0 and computes the address of the 10th
> element in line 3.

LLVM allows those GEP's to evaluate to the same value.

-Eli