[llvm] 79ebe71 - [NFC][LLVM][Intrinsics] Add `hasStructReturnType` helper (#195457)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 05:37:07 PDT 2026
Author: Rahul Joshi
Date: 2026-05-03T05:37:02-07:00
New Revision: 79ebe710898d70f0147903806bfb38776cbd6b8f
URL: https://github.com/llvm/llvm-project/commit/79ebe710898d70f0147903806bfb38776cbd6b8f
DIFF: https://github.com/llvm/llvm-project/commit/79ebe710898d70f0147903806bfb38776cbd6b8f.diff
LOG: [NFC][LLVM][Intrinsics] Add `hasStructReturnType` helper (#195457)
Add a helper function to query if an intrinsic has a struct return type
and use it in AutoUpgrade
Added:
Modified:
llvm/include/llvm/IR/Intrinsics.h
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Intrinsics.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index 4ab2334b16abd..c56ada4fd4f71 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -257,6 +257,9 @@ namespace Intrinsic {
}
};
+ /// Returns true if \p id has a struct return type.
+ LLVM_ABI bool hasStructReturnType(ID id);
+
/// Return the IIT table descriptor for the specified intrinsic into an array
/// of IITDescriptors.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id,
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 433300ec63585..5fed947f9314d 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1869,10 +1869,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
// intrinsics declared to return a struct, not for intrinsics with
// overloaded return type, in which case the exact struct type will be
// mangled into the name.
- SmallVector<Intrinsic::IITDescriptor> Desc;
- Intrinsic::getIntrinsicInfoTableEntries(F->getIntrinsicID(), Desc);
- if (Desc.front().Kind == Intrinsic::IITDescriptor::Struct) {
- auto *FT = F->getFunctionType();
+ if (Intrinsic::hasStructReturnType(F->getIntrinsicID())) {
+ FunctionType *FT = F->getFunctionType();
auto *NewST = StructType::get(ST->getContext(), ST->elements());
auto *NewFT = FunctionType::get(NewST, FT->params(), FT->isVarArg());
std::string Name = F->getName().str();
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 89b5fc59a0168..22f2a8078f500 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -1154,6 +1154,13 @@ static bool isSignatureValid(FunctionType *FTy,
return true;
}
+bool Intrinsic::hasStructReturnType(ID id) {
+ using namespace Intrinsic;
+ SmallVector<IITDescriptor> Table;
+ getIntrinsicInfoTableEntries(id, Table);
+ return !Table.empty() && Table[0].Kind == IITDescriptor::Struct;
+}
+
bool Intrinsic::isSignatureValid(Intrinsic::ID ID, FunctionType *FT,
SmallVectorImpl<Type *> &OverloadTys,
raw_ostream &OS) {
More information about the llvm-commits
mailing list