[llvm] [GlobalISel] Use getCmpLibcallReturnType() for FCMP libcalls (PR #226813)
Kiroo via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 10:33:03 PDT 2026
https://github.com/zlfn created https://github.com/llvm/llvm-project/pull/226813
The GCC soft-float comparison routines return `CMPtype`, not always `i32`.
https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html#Comparison-functions-1
> 3.2.3 Comparison functions
> There are two sets of basic comparison functions.
> ...
> Runtime Function: CMPtype __unordsf2 (float a, float b)
> Runtime Function: CMPtype __unorddf2 (double a, double b)
> Runtime Function: CMPtype __unordtf2 (long double a, long double b)
> ...
The FCMP libcall result was hardcoded to i32. Use `getCmpLibcallReturnType()`, as SelectionDAG does.
NFC for in-tree targets.
Co-authored-by: Thorbjørn Ravn Andersen <tra at ravnand.dk>
>From 269842f709e7c248092f92da99fef4d65b4c579b Mon Sep 17 00:00:00 2001
From: zlfn <ung at zlfn.space>
Date: Mon, 28 Sep 2026 02:25:56 +0900
Subject: [PATCH] [GlobalISel] Use getCmpLibcallReturnType() for FCMP libcalls
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The FCMP libcall result was hardcoded to i32. Use the target hook, as
SelectionDAG does. NFC for in-tree targets.
Co-authored-by: Thorbjørn Ravn Andersen <tra at ravnand.dk>
---
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 502d2f4e98c97..9b9cb69d6f335 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -1190,6 +1190,7 @@ LegalizerHelper::createFCMPLibcall(MachineInstr &MI,
const Register DstReg = Cmp->getReg(0);
LLT DstTy = MRI.getType(DstReg);
const auto Cond = Cmp->getCond();
+ Type *RetTy = EVT(TLI.getCmpLibcallReturnType()).getTypeForEVT(Ctx);
// Reference:
// https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html#Comparison-functions-1
@@ -1197,12 +1198,12 @@ LegalizerHelper::createFCMPLibcall(MachineInstr &MI,
const auto BuildLibcall = [&](const RTLIB::Libcall Libcall,
const CmpInst::Predicate ICmpPred,
const DstOp &Res) -> Register {
- // FCMP libcall always returns an i32, and needs an ICMP with #0.
- LLT TempLLT = LLT::integer(32);
+ // FCMP libcall returns an integer, and needs an ICMP with #0.
+ LLT TempLLT = LLT::integer(RetTy->getIntegerBitWidth());
Register Temp = MRI.createGenericVirtualRegister(TempLLT);
// Generate libcall, holding result in Temp
const auto Status = createLibcall(
- Libcall, {Temp, Type::getInt32Ty(Ctx), 0},
+ Libcall, {Temp, RetTy, 0},
{{Cmp->getLHSReg(), OpType, 0}, {Cmp->getRHSReg(), OpType, 1}},
LocObserver, &MI);
if (Status != Legalized)
More information about the llvm-commits
mailing list