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

via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 09:11:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Rahul Joshi (jurahul)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/195457.diff


3 Files Affected:

- (modified) llvm/include/llvm/IR/Intrinsics.h (+5) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+2-4) 
- (modified) llvm/lib/IR/Intrinsics.cpp (+9) 


``````````diff
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) {

``````````

</details>


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


More information about the llvm-commits mailing list