llvm-project/llvm/test/CodeGen/Mips/llrint-conv.ll
Trevor Gross c63d2953a0
[SelectionDAG,GISel] Add f16 soft promotion for lrint, lround, llrint, and llround (#152684)
On platforms that soft promote `half`, using `lrint` intrinsics crashes
with the following:

    SoftPromoteHalfOperand Op #0: t5: i32 = lrint t4

    LLVM ERROR: Do not know how to soft promote this operator's operand!
PLEASE submit a bug report to
https://github.com/llvm/llvm-project/issues/ and include the crash
backtrace.
    Stack dump:
0. Program arguments:
/Users/tmgross/Documents/projects/llvm/llvm-build/bin/llc
-mtriple=riscv32
    1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on
function '@test_lrint_ixx_f16'

Resolve this by adding a soft promotion. GISel is included since tests
cover both.

Fixes crash tests added in
https://github.com/llvm/llvm-project/pull/152662 for targets that use
`softPromoteHalfType`.

Co-authored-by: Folkert de Vries <folkert@folkertdev.nl>
2026-01-08 12:40:10 +01:00

75 lines
1.7 KiB
LLVM

; RUN: llc < %s -mtriple=mips64el -mattr=+soft-float | FileCheck %s
; RUN: llc < %s -mtriple=mips -mattr=+soft-float | FileCheck %s
define signext i32 @testmswh(half %x) {
; CHECK-LABEL: testmswh:
; CHECK: jal llrintf
entry:
%0 = tail call i64 @llvm.llrint.i64.f16(half %x)
%conv = trunc i64 %0 to i32
ret i32 %conv
}
define i64 @testmsxh(half %x) {
; CHECK-LABEL: testmsxh:
; CHECK: jal llrintf
entry:
%0 = tail call i64 @llvm.llrint.i64.f16(half %x)
ret i64 %0
}
define signext i32 @testmsws(float %x) {
; CHECK-LABEL: testmsws:
; CHECK: jal llrintf
entry:
%0 = tail call i64 @llvm.llrint.i64.f32(float %x)
%conv = trunc i64 %0 to i32
ret i32 %conv
}
define i64 @testmsxs(float %x) {
; CHECK-LABEL: testmsxs:
; CHECK: jal llrintf
entry:
%0 = tail call i64 @llvm.llrint.i64.f32(float %x)
ret i64 %0
}
define signext i32 @testmswd(double %x) {
; CHECK-LABEL: testmswd:
; CHECK: jal llrint
entry:
%0 = tail call i64 @llvm.llrint.i64.f64(double %x)
%conv = trunc i64 %0 to i32
ret i32 %conv
}
define i64 @testmsxd(double %x) {
; CHECK-LABEL: testmsxd:
; CHECK: jal llrint
entry:
%0 = tail call i64 @llvm.llrint.i64.f64(double %x)
ret i64 %0
}
define signext i32 @testmswl(fp128 %x) {
; CHECK-LABEL: testmswl:
; CHECK: jal llrintl
entry:
%0 = tail call i64 @llvm.llrint.i64.f128(fp128 %x)
%conv = trunc i64 %0 to i32
ret i32 %conv
}
define i64 @testmsll(fp128 %x) {
; CHECK-LABEL: testmsll:
; CHECK: jal llrintl
entry:
%0 = tail call i64 @llvm.llrint.i64.f128(fp128 %x)
ret i64 %0
}
declare i64 @llvm.llrint.i64.f32(float) nounwind readnone
declare i64 @llvm.llrint.i64.f64(double) nounwind readnone
declare i64 @llvm.llrint.i64.f128(fp128) nounwind readnone