[llvm] [CodeGen] Return an IR type from getCmpLibcallReturnType (NFC) (PR #227192)
Kiroo via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 22:49:40 PDT 2026
https://github.com/zlfn created https://github.com/llvm/llvm-project/pull/227192
Refactor `getCmpLibcallReturnType()` to return an IR `IntegerType`, as suggested by @arsenm in #226813.
This hook is only overriden by AVR and MSP430, so only those two targets are changed.
>From cfb8291f7a57d0119ef4952883cf55ed864ead11 Mon Sep 17 00:00:00 2001
From: zlfn <ung at zlfn.space>
Date: Tue, 29 Sep 2026 14:37:17 +0900
Subject: [PATCH] [CodeGen] Return an IR type from getCmpLibcallReturnType
(NFC)
---
llvm/include/llvm/CodeGen/TargetLowering.h | 10 +++++-----
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 2 +-
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 2 +-
llvm/lib/Target/AVR/AVRISelLowering.h | 4 ++--
llvm/lib/Target/MSP430/MSP430ISelLowering.h | 4 ++--
5 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 18255b429d995..8915f7ce7a85a 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1014,11 +1014,11 @@ class LLVM_ABI TargetLoweringBase {
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
EVT VT) const;
- /// Return the ValueType for comparison libcalls. Comparison libcalls include
- /// floating point comparison calls, and Ordered/Unordered check calls on
- /// floating point numbers.
- virtual MVT::SimpleValueType getCmpLibcallReturnType() const {
- return MVT::i32; // return the default value
+ /// Return the integer type returned by comparison libcalls. Comparison
+ /// libcalls include floating point comparison calls, and Ordered/Unordered
+ /// check calls on floating point numbers.
+ virtual IntegerType *getCmpLibcallReturnType(LLVMContext &Ctx) const {
+ return Type::getInt32Ty(Ctx);
}
/// For targets without i1 registers, this gives the nature of the high-bits
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 9b9cb69d6f335..32ec779c71a9e 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -1190,7 +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);
+ Type *RetTy = TLI.getCmpLibcallReturnType(Ctx);
// Reference:
// https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html#Comparison-functions-1
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 868171e45be86..672cfe97d3366 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -519,7 +519,7 @@ void TargetLowering::softenSetCCOperands(SelectionDAG &DAG, EVT VT,
#undef FP_CMP_LIBCALL
// Use the target specific return value for comparison lib calls.
- EVT RetVT = getCmpLibcallReturnType();
+ EVT RetVT = EVT::getEVT(getCmpLibcallReturnType(*DAG.getContext()));
SDValue Ops[2] = {NewLHS, NewRHS};
TargetLowering::MakeLibCallOptions CallOptions;
EVT OpsVT[2] = { OldLHS.getValueType(),
diff --git a/llvm/lib/Target/AVR/AVRISelLowering.h b/llvm/lib/Target/AVR/AVRISelLowering.h
index ae99f654aba00..4ad386db00183 100644
--- a/llvm/lib/Target/AVR/AVRISelLowering.h
+++ b/llvm/lib/Target/AVR/AVRISelLowering.h
@@ -33,8 +33,8 @@ class AVRTargetLowering : public TargetLowering {
return MVT::i8;
}
- MVT::SimpleValueType getCmpLibcallReturnType() const override {
- return MVT::i8;
+ IntegerType *getCmpLibcallReturnType(LLVMContext &Ctx) const override {
+ return Type::getInt8Ty(Ctx);
}
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
diff --git a/llvm/lib/Target/MSP430/MSP430ISelLowering.h b/llvm/lib/Target/MSP430/MSP430ISelLowering.h
index d906c3817bbe5..6e90569b0752e 100644
--- a/llvm/lib/Target/MSP430/MSP430ISelLowering.h
+++ b/llvm/lib/Target/MSP430/MSP430ISelLowering.h
@@ -29,8 +29,8 @@ namespace llvm {
return MVT::i8;
}
- MVT::SimpleValueType getCmpLibcallReturnType() const override {
- return MVT::i16;
+ IntegerType *getCmpLibcallReturnType(LLVMContext &Ctx) const override {
+ return Type::getInt16Ty(Ctx);
}
/// LowerOperation - Provide custom lowering hooks for some operations.
More information about the llvm-commits
mailing list