[llvm] DAG: Gracefully diagnose missing lrint/llrint/lround/llround libcall (PR #215032)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 8 16:04:59 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/215032
Avoid hitting the fatal error in makeLibCall by emitting a diagnostic
if the library call is unsupported.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
>From c5d85d8ab23bac8c39ed3de003cdd86499c104bc Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 9 Aug 2026 01:00:09 +0200
Subject: [PATCH] DAG: Gracefully diagnose missing lrint/llrint/lround/llround
libcall
Avoid hitting the fatal error in makeLibCall by emitting a diagnostic
if the library call is unsupported.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
.../SelectionDAG/LegalizeIntegerTypes.cpp | 16 ++++++++--
.../CodeGen/X86/xrint-no-libcall-error.ll | 29 +++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/xrint-no-libcall-error.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 2fee0b280ed9b..7d7c624d030d3 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -4570,11 +4570,21 @@ void DAGTypeLegalizer::ExpandIntRes_XROUND_XRINT(SDNode *N, SDValue &Lo,
EVT RetVT = N->getValueType(0);
+ RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
+ if (LCImpl == RTLIB::Unsupported) {
+ DAG.getContext()->emitError(Twine("no libcall available for ") +
+ N->getOperationName(&DAG));
+ SDValue Poison = DAG.getPOISON(N->getValueType(0));
+ SplitInteger(Poison, Lo, Hi);
+ if (N->isStrictFPOpcode())
+ ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+ return;
+ }
+
TargetLowering::MakeLibCallOptions CallOptions;
CallOptions.setIsSigned(true);
- std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
- Op, CallOptions, dl,
- Chain);
+ std::pair<SDValue, SDValue> Tmp =
+ TLI.makeLibCall(DAG, LCImpl, RetVT, Op, CallOptions, dl, Chain);
SplitInteger(Tmp.first, Lo, Hi);
if (N->isStrictFPOpcode())
diff --git a/llvm/test/CodeGen/X86/xrint-no-libcall-error.ll b/llvm/test/CodeGen/X86/xrint-no-libcall-error.ll
new file mode 100644
index 0000000000000..e5eefe38ded70
--- /dev/null
+++ b/llvm/test/CodeGen/X86/xrint-no-libcall-error.ll
@@ -0,0 +1,29 @@
+; RUN: not llc -mtriple=i686-unknown-unknown -filetype=null %s 2>&1 | FileCheck %s
+
+; The i64-returning llrint/llround expander splits the integer result
+; and calls the ppcf128 libcall, which is not available. This should
+; emit a proper diagnostic rather than fatal erroring.
+
+; CHECK: error: no libcall available for llrint
+define i64 @test_llrint_ppcf128(ppc_fp128 %x) nounwind {
+ %r = call i64 @llvm.llrint.i64.ppcf128(ppc_fp128 %x)
+ ret i64 %r
+}
+
+; CHECK: error: no libcall available for llround
+define i64 @test_llround_ppcf128(ppc_fp128 %x) nounwind {
+ %r = call i64 @llvm.llround.i64.ppcf128(ppc_fp128 %x)
+ ret i64 %r
+}
+
+; CHECK: error: no libcall available for strict_llrint
+define i64 @test_strict_llrint_ppcf128(ppc_fp128 %x) nounwind strictfp {
+ %r = call i64 @llvm.experimental.constrained.llrint.i64.ppcf128(ppc_fp128 %x, metadata !"round.tonearest", metadata !"fpexcept.strict")
+ ret i64 %r
+}
+
+; CHECK: error: no libcall available for strict_llround
+define i64 @test_strict_llround_ppcf128(ppc_fp128 %x) nounwind strictfp {
+ %r = call i64 @llvm.experimental.constrained.llround.i64.ppcf128(ppc_fp128 %x, metadata !"fpexcept.strict")
+ ret i64 %r
+}
More information about the llvm-commits
mailing list