| Issue |
244519
|
| Summary |
[SelectionDAG] Assertion "Wrong operand type!" in verifyNode at -O3: select of `trunc <16 x i256>` splat to `<16 x i8>`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
haoxintu
|
## Description
```c
_BitInt(2) r;
void
f (long x, long y)
{
_BitInt(512) b = (_BitInt(512)) x * 5;
_BitInt(8) c = y;
_BitInt(256) arr[23];
_BitInt(2) acc = 0;
for (int h = 0; h < 23; h++)
arr[h] = (_BitInt(256)) b * h + c;
for (int h = 0; h < 23; h++)
{
_BitInt(6) e = arr[h];
_BitInt(6) i = b;
_BitInt(56) j;
switch (i)
{
case 1:
j = 0;
break;
case 4:
j = e;
break;
default:
j = e;
}
acc = acc + j;
}
r = acc;
}
```
```
$ clang -O3 -c repro.c # -O0/-O1/-O2/-Os are fine
clang: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1241: void llvm::SelectionDAG::verifyNode(llvm::SDNode*) const:
Assertion `(Op.getValueType() == EltVT || (EltVT.isInteger() && Op.getValueType().isInteger() && EltVT.bitsLE(Op.getValueType()))) && "Wrong operand type!"' failed.
...
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@f'
```
The code is valid. `clang -Wall -Wextra` and `gcc -Wall -Wextra` are clean.
`llc -O3` on the IR that -O3 produces for the vectorized loop crashes the same way (reduced with llvm-reduce):
```llvm
define <16 x i8> @f3(i512 %conv2) {
entry:
%conv11 = trunc i512 %conv2 to i256
%0 = insertelement <2 x i256> zeroinitializer, i256 %conv11, i64 0
%trunc = trunc i512 %conv2 to i6
%cond = icmp eq i6 %trunc, 0
%1 = shufflevector <2 x i256> %0, <2 x i256> zeroinitializer, <16 x i32> <i32 0, i32 0, i32 0, i32 0, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
%2 = trunc <16 x i256> %1 to <16 x i8>
%common.ret1.op = select i1 %cond, <16 x i8> zeroinitializer, <16 x i8> %2
ret <16 x i8> %common.ret1.op
}
```
A BUILD_VECTOR (or similar) gets an operand whose type is narrower than the vector element type while legalizing the truncate of the i256 splat.
Reproduced in Godbolt (x86-64 clang assertions trunk, -O3): https://godbolt.org/z/Wvnfrbdax
Thanks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs