[NVPTX] "Cannot select: v2i32 = and" when storing `trunc <2 x i32> to <2 x i1>` on sm_100 and newer
Storing a <2 x i1> that comes from trunc <2 x i32> crashes instruction selection for sm_100a / sm_120a. sm_90a compiles
it. Seen with LLVM 22.1.8, 23.1.4 and main (5916210dbe10), at -O0 and -O3; LLVM 20.1.8 is fine. Masks from icmp / fcmp
and other element widths / lane counts compile.
target triple = "nvptx64-nvidia-cuda"
define ptx_kernel void @k(ptr addrspace(1) %in, ptr addrspace(1) %out) {
%v = load <2 x i32>, ptr addrspace(1) %in, align 8
%r = trunc <2 x i32> %v to <2 x i1>
store <2 x i1> %r, ptr addrspace(1) %out, align 1
ret void
}
$ llc -mtriple=nvptx64-nvidia-cuda -mcpu=sm_100a store_v2i1.ll -o -
LLVM ERROR: Cannot select: 0x...: v2i32 = and 0x..., 0x...
0x...: v2i32,ch = load<(load (s64) from %ir.in, addrspace 1)> 0x..., 0x..., poison:i64
0x...: i64,ch = load<(dereferenceable invariant load (s64), addrspace 101)> 0x..., 0x..., poison:i64
0x...: i64 = NVPTXISD::Symbol MCSymbol:i64
0x...: v2i32 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>
In function: k
opt -O3 before llc does not avoid it (same error).
The i1-vector store legalization masks the lanes with a v2i32 AND (and x, <1, 1>) that has no selection pattern on
sm_100+. A guess (not verified): v2i32 is a legal type there since #153478, and this AND has neither a pattern nor an
expansion for v2i32. llvm.bswap.v2i32 crashes the same way ("Cannot select: v2i32 = bswap") on the same archs, so
other v2i32 operations may be missing too.
Sorry the same issue was submitted twice.