<div dir="ltr">Hi,<div><br></div><div>Let's have a simple program:</div><div><div>define i32 @main(i32 %n, i64 %idx) {</div><div>  %idxSafe = trunc i64 %idx to i5</div><div>  %r = extractelement <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, i64 %idx</div><div>  ret i32 %r</div><div>}</div></div><div><br></div><div>The assembly of that would be:</div><div><div><span class="Apple-tab-span" style="white-space:pre">      </span>pcmpeqd<span class="Apple-tab-span" style="white-space:pre">     </span>%xmm0, %xmm0</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movdqa<span class="Apple-tab-span" style="white-space:pre">      </span>%xmm0, -24(%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>movl<span class="Apple-tab-span" style="white-space:pre">        </span>-24(%rsp,%rsi,4), %eax</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>retq</div></div><div><br></div><div>The language reference states that the extractelement instruction produces undefined value in case the index argument is invalid (our case). But the implementation simply dumps the vector to the stack memory, calculates the memory offset out of the index value and tries to access the memory. That causes the crash.</div><div><br></div><div>The workaround is to trunc the index value before extractelement (see %idxSafe). But what should be the ultimate solution?</div><div><br></div><div>- PB</div></div>