[LLVMdev] Why int variable get promoted to i64
Joe Abbey
joe.abbey at gmail.com
Fri Aug 19 05:16:22 PDT 2011
Because you are compiling for a 64-bit system which uses LP64. As such pointers are 64-bit in length... while integers remain defined as 32-bits.
So why 64-bits for i? The compiler is treating index variables special. Index variables need to be able to index 64-bits of space and in fact you'll see the promotion here:
for.body: ; preds = %for.cond
%tmp2 = load i32* %i ; <i32> [#uses=1]
%tmp3 = load i32** %x.addr ; <i32*> [#uses=1]
%idxprom = sext i32 %tmp2 to i64 ; <i64> [#uses=1]
%arrayidx = getelementptr inbounds i32* %tmp3, i64 %idxprom ; <i32*> [#uses=1]
Cheers,
Joe
On Aug 19, 2011, at 5:32 AM, 陳韋任 wrote:
> int test(int x[], int y[], int n) {
> int i = 0;
> int sum = 0;
> for ( ; i < n; i++) {
> sum += x[i] * y[i];
> }
> return sum;
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110819/c64b2680/attachment.html>
More information about the llvm-dev
mailing list