<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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. <div><br></div><div>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:<div><br></div><div><span class="Apple-style-span" style="font-family: Times; "><pre>for.body: ; preds = %for.cond
%tmp2 = <span class="llvm_keyword" style="font-weight: bold; color: blue; ">load</span> <span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>* %i ; <<span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>> [#uses=1]
%tmp3 = <span class="llvm_keyword" style="font-weight: bold; color: blue; ">load</span> <span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>** %x.addr ; <<span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>*> [#uses=1]
%idxprom = <span class="llvm_keyword" style="font-weight: bold; color: blue; ">sext</span> <span class="llvm_type" style="font-style: oblique; color: green; ">i32</span> %tmp2 <span class="llvm_keyword" style="font-weight: bold; color: blue; ">to</span> <span class="llvm_type" style="font-style: oblique; color: green; ">i64</span> ; <<span class="llvm_type" style="font-style: oblique; color: green; ">i64</span>> [#uses=1]
%arrayidx = <span class="llvm_keyword" style="font-weight: bold; color: blue; ">getelementptr</span> inbounds <span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>* %tmp3, <span class="llvm_type" style="font-style: oblique; color: green; ">i64</span> %idxprom ; <<span class="llvm_type" style="font-style: oblique; color: green; ">i32</span>*> [#uses=1]</pre></span><div><div><br></div><div>Cheers,</div><div><br></div><div>Joe</div><div><br><div><div>On Aug 19, 2011, at 5:32 AM, 陳韋任 wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">int test(int x[], int y[], int n) {<br> int i = 0;<br> int sum = 0;<br> for ( ; i < n; i++) {<br> sum += x[i] * y[i];<br> }<br> return sum;<br>}</span></blockquote></div><br></div></div></div></div></body></html>