[llvm] [NFC][LLVM][Intrinsics] Add `hasStructReturnType` helper (PR #195457)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 07:57:36 PDT 2026


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/195457

Add a helper function to query if an intrinsic has a struc return type and use it in AutoUpgrade

>From a6d4a69ea02458a019e7b30c87ec907c72c507dc Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 2 May 2026 07:55:25 -0700
Subject: [PATCH] [NFC][LLVM][Intrinsics] Add `hasStructReturnType` helper

Add a helper function to query if an intrinsic has a struc return type
and use it in AutoUpgrade
---
 llvm/include/llvm/IR/Intrinsics.h | 5 +++++
 llvm/lib/IR/AutoUpgrade.cpp       | 6 ++----
 llvm/lib/IR/Intrinsics.cpp        | 9 +++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index a69f23e889318..ecd9a4bf825ec 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -257,6 +257,11 @@ namespace Intrinsic {
     }
   };
 
+  /// Returns true if \p id has a struct return type in the first component of
+  /// the return value, and the number of struct elements in the second
+  /// component of the return value.
+  LLVM_ABI std::pair<bool, uint32_t> 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..c041f717013e0 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()).first) {
+      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 c5a0531a089b6..176b08cf897e5 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -1143,6 +1143,15 @@ bool Intrinsic::matchIntrinsicSignature(
   return false;
 }
 
+std::pair<bool, uint32_t> Intrinsic::hasStructReturnType(ID id) {
+  using namespace Intrinsic;
+  SmallVector<IITDescriptor> Table;
+  getIntrinsicInfoTableEntries(id, Table);
+  if (!Table.empty() && Table[0].Kind == IITDescriptor::Struct)
+    return {true, Table[0].StructNumElements};
+  return {false, 0};
+}
+
 bool Intrinsic::isSignatureValid(Intrinsic::ID ID, FunctionType *FT,
                                  SmallVectorImpl<Type *> &OverloadTys,
                                  raw_ostream &OS) {



More information about the llvm-commits mailing list