[llvm] 7a931b5 - [GlobalISel] Use getCmpLibcallReturnType() for FCMP libcalls (NFC) (#226813)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 00:45:43 PDT 2026
Author: Kiroo (Chanung)
Date: 2026-09-28T09:45:36+02:00
New Revision: 7a931b5ec3f305a51f702cb0702d2a07f7e74c0b
URL: https://github.com/llvm/llvm-project/commit/7a931b5ec3f305a51f702cb0702d2a07f7e74c0b
DIFF: https://github.com/llvm/llvm-project/commit/7a931b5ec3f305a51f702cb0702d2a07f7e74c0b.diff
LOG: [GlobalISel] Use getCmpLibcallReturnType() for FCMP libcalls (NFC) (#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>
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Removed:
################################################################################
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