Differentiate array access at IR level

Hello Johannes,

Thanks for your suggestion! The ScalarEvolution analysis is very helpful.

I had a follow-up question. It would be great if you can take a look.

%11 = load float*, float** %a.addr, align 8, !dbg !954
%12 = load i32, i32* %i, align 4, !dbg !955
%sub = sub nsw i32 %12, 1, !dbg !956
%idxprom7 = sext i32 %sub to i64, !dbg !954
%arrayidx8 = getelementptr inbounds float, float* %11, i64 %idxprom7, !dbg !954

For the above code, the result for %idxprom7 is: (-1 + (sext i32 %12 to i64)). Just wondering if you have any suggestion that I can replace (sext i32 %12 to i64) with symbol %i

Thanks,
Michael

Hello Johannes,

Thanks for your suggestion! The ScalarEvolution analysis is very helpful.

I had a follow-up question. It would be great if you can take a look.

%11 = load float*, float** %a.addr, align 8, !dbg !954
%12 = load i32, i32* %i, align 4, !dbg !955
%sub = sub nsw i32 %12, 1, !dbg !956
%idxprom7 = sext i32 %sub to i64, !dbg !954
%arrayidx8 = getelementptr inbounds float, float* %11, i64 %idxprom7, !dbg !954

For the above code, the result for %idxprom7 is: (-1 + (sext i32 %12
to i64))<nsw>. Just wondering if you have any suggestion that I can
replace (sext i32 %12 to i64) with symbol %i

You need to "effectively" run mem2reg on your code first. If your code
was build without -O{1,2,3} the functions have probably the `optnone`
attribute. Remove it from the file and run mem2reg afterwards.

Maybe take a look at the create_ll.sh script (see below) as it shows how
.c -> .ll transformation should be done.

In the snippet, %i represents an address, but %12 represents the value
loaded from that address (and %idxprom7 an index computed from %12).
You probably don't want to mix the two.

What I assume from you question is that you would like to get rid of
the sign-extension (sext). It is part of the semantics, so it is
probably unwise to just ignore it, it it depends on what you actually
want to do. You could write you original program to use int64_t for
the variable i.

Michael