<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72539>72539</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SelectionDAG] Assertion `Index < Length && "Invalid index!"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:crash,
llvm:SelectionDAG
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
RKSimon
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
danilaml
</td>
</tr>
</table>
<pre>
LLC asserts on the following IR turing isel:
```llvm
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "x86_64-unknown-linux-gnu"
define void @test(<8 x i32> %insertelement) #0 {
bb:
%load671 = load i8, ptr addrspace(1) null, align 1
%shufflevector = shufflevector <8 x i32> %insertelement, <8 x i32> zeroinitializer, <8 x i32> zeroinitializer
%xor68 = xor <8 x i32> %shufflevector, <i32 7, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
%call69 = call i32 @llvm.vector.reduce.xor.v8i32(<8 x i32> %xor68)
%trunc70 = trunc i32 %call69 to i8
%xor71 = xor i8 %load671, %trunc70
store i8 %xor71, ptr addrspace(1) null, align 1
ret void
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.xor.v8i32(<8 x i32>) #1
attributes #0 = { "target-cpu"="skylake-avx512" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
reproduces with simple `llc`, no additional parameters required. Seems to be an issue in the code added in https://github.com/llvm/llvm-project/commit/5dff767c25041c1dfbba42520ce59e8f837b19ad , where `SizeInBits` is 8 (truncated load from constant pool), but `SrcEltSizeInBits` is higher (128, I think), resulting in `NumSrcElts` being zero (so zero size vector is allocated and then used in `unsigned SrcEltSizeInBits = SrcEltBits[0].getBitWidth();`).
Godbolt link: https://god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