llvm-project
llvm-project copied to clipboard
[NVPTX] "Cannot select: i64 = lround" for llvm.lround / llvm.llround on half and bfloat
llvm.lround and llvm.llround on half and bfloat crash ISel at -O0 and -O3 on sm_50 to sm_103a (LLVM 20.1.8, 22.1.8, 23.1.4, main 2d6c6a1ec82b, nightly 2026-11-04); float and double compile.
target triple = "nvptx64-nvidia-cuda"
define i64 @f(half %x) {
%r = call i64 @llvm.lround.i64.f16(half %x)
ret i64 %r
}
declare i64 @llvm.lround.i64.f16(half)
$ llc -mcpu=sm_100a lround.ll -o -
LLVM ERROR: Cannot select: 0x...: i64 = lround 0x...
Possible fix: NVPTXISelLowering.cpp:1040 sets Expand for {ISD::LROUND, ISD::LLROUND} only on {MVT::f32, MVT::f64}, so f16 and bf16 stay Legal with no pattern; add them to that list or promote them to f32.
we get hit by the following assertion if we try to promote f16 and bf16 to f32 for LROUND and LLROUND, i'm not sure what's happening here.
assert(getOperationAction(Op, VT) == Promote &&
"This operation isn't promoted!");
going by Expanding them.
the issue i ran into seems to be very close to #236348