llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[NVPTX] "Cannot select: i64 = lround" for llvm.lround / llvm.llround on half and bfloat

Open jeffchen006 opened this issue 1 month ago • 2 comments

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.

jeffchen006 avatar Nov 05 '26 00:11 jeffchen006

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.

StarOne01 avatar Nov 08 '26 01:11 StarOne01

the issue i ran into seems to be very close to #236348

StarOne01 avatar Nov 08 '26 13:11 StarOne01