[llvm] 0597f3e - DAG: Gracefully diagnose missing lrint/llrint/lround/llround libcall (#215032)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 02:55:59 PDT 2026


Author: Matt Arsenault
Date: 2026-08-11T11:55:54+02:00
New Revision: 0597f3eb9fce36334ff668b3f28ce136ed0bbac8

URL: https://github.com/llvm/llvm-project/commit/0597f3eb9fce36334ff668b3f28ce136ed0bbac8
DIFF: https://github.com/llvm/llvm-project/commit/0597f3eb9fce36334ff668b3f28ce136ed0bbac8.diff

LOG: DAG: Gracefully diagnose missing lrint/llrint/lround/llround libcall (#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>

Added: 
    llvm/test/CodeGen/X86/xrint-no-libcall-error.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index b4c2c8376dbe6..2f409a704d186 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -4586,11 +4586,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..3439fc76be722
--- /dev/null
+++ b/llvm/test/CodeGen/X86/xrint-no-libcall-error.ll
@@ -0,0 +1,28 @@
+; RUN: not llc -mtriple=i686-unknown-unknown -filetype=null %s 2>&1 | FileCheck %s
+
+; Make sure these missing libcalls 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