[llvm] [LLVM][Verifier] Improve diagnostic messages for Intrinsics in Verifier (PR #185641)

Kirill Vedernikov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 03:55:48 PDT 2026


https://github.com/kvederni updated https://github.com/llvm/llvm-project/pull/185641

>From 179f410b15638e0a8dad7cd68cd820c14b7e51a4 Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Tue, 10 Mar 2026 12:53:28 +0100
Subject: [PATCH 1/7] [LLVM][Verifier] Improve diagnostic messages for
 Intrinsics in Verifier

Introduce IntrinsicDiagnosticsProvider, a base class that allows
to append detailed information to the standard LLVM error messages
emitted when an intrinsic is called or declared with an incorrect
signature.

The original messages are preserved unchanged. The NVVM detail is only
appended when the intrinsic name starts with "llvm.nvvm.". Non-NVVM
intrinsics produce the standard messages and all existing LLVM tests
pass unmodified.
---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h   |  72 ++++++++++
 llvm/lib/AsmParser/LLParser.cpp               |  13 +-
 llvm/lib/IR/CMakeLists.txt                    |   2 +
 llvm/lib/IR/IntrinsicDiagnostics.cpp          |  51 ++++++++
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp      | 123 ++++++++++++++++++
 llvm/lib/IR/Verifier.cpp                      |  35 ++++-
 .../test/CodeGen/NVPTX/sad-intrins-invalid.ll |  69 ++++++++++
 7 files changed, 357 insertions(+), 8 deletions(-)
 create mode 100644 llvm/include/llvm/IR/IntrinsicDiagnostics.h
 create mode 100644 llvm/lib/IR/IntrinsicDiagnostics.cpp
 create mode 100644 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
 create mode 100644 llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
new file mode 100644
index 0000000000000..31fd31818bcee
--- /dev/null
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -0,0 +1,72 @@
+//===- IntrinsicDiagnostics.h - Intrinsic diagnostic hooks ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines IntrinsicDiagnosticsProvider, a virtual base class that targets
+// can subclass to append extra detail lines to intrinsic signature mismatch
+// diagnostics.  The default implementations are no-ops, leaving the standard
+// upstream message unchanged.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_INTRINSICDIAGNOSTICS_H
+#define LLVM_IR_INTRINSICDIAGNOSTICS_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+class FunctionType;
+class raw_ostream;
+
+/// Interface for appending target-specific detail lines to diagnostics emitted
+/// when an intrinsic is called or declared with an incorrect signature.
+///
+/// Subclasses are registered via \c registerProvider.  At diagnostic emission
+/// time each registered provider may write additional lines to the output
+/// stream; the standard upstream message is always emitted first by the caller.
+class IntrinsicDiagnosticsProvider {
+public:
+  virtual ~IntrinsicDiagnosticsProvider() = default;
+
+  /// Optionally appends detail for a call-site signature mismatch.
+  virtual void getSignatureMismatch(StringRef IntrName, FunctionType *DeclFTy,
+                                    FunctionType *CallFTy,
+                                    raw_ostream &OS) const {}
+
+  /// Optionally appends detail for a verifier return-type mismatch.
+  virtual void getReturnTypeMismatch(StringRef IntrName, FunctionType *IFTy,
+                                     raw_ostream &OS) const {}
+
+  /// Optionally appends detail for a verifier argument-type mismatch.
+  virtual void getArgTypeMismatch(StringRef IntrName, FunctionType *IFTy,
+                                  raw_ostream &OS) const {}
+
+  /// Optionally appends detail for a parser-level signature mismatch.
+  /// \p ExpectedFTy is the canonical intrinsic type, or null for overloaded
+  /// intrinsics.
+  virtual void getParserMismatch(StringRef IntrName, FunctionType *CallFTy,
+                                 FunctionType *ExpectedFTy,
+                                 raw_ostream &OS) const {}
+
+  /// Registers \p P as a diagnostics provider.  Does not take ownership;
+  /// \p P must outlive all diagnostic queries.
+  static void registerProvider(IntrinsicDiagnosticsProvider *P);
+
+  /// Asks all registered providers to append detail to \p OS.
+  static void querySignatureMismatch(StringRef IntrName, FunctionType *DeclFTy,
+                                     FunctionType *CallFTy, raw_ostream &OS);
+  static void queryReturnTypeMismatch(StringRef IntrName, FunctionType *IFTy,
+                                      raw_ostream &OS);
+  static void queryArgTypeMismatch(StringRef IntrName, FunctionType *IFTy,
+                                   raw_ostream &OS);
+  static void queryParserMismatch(StringRef IntrName, FunctionType *CallFTy,
+                                  FunctionType *ExpectedFTy, raw_ostream &OS);
+};
+
+} // namespace llvm
+
+#endif // LLVM_IR_INTRINSICDIAGNOSTICS_H
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 917aecb47590d..661694974986f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -36,6 +36,7 @@
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/LLVMContext.h"
@@ -354,7 +355,17 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
           if (!UpgradeIntrinsicFunction(TmpF, NewF)) {
             if (IID == Intrinsic::not_intrinsic)
               return error(Info.second, "unknown intrinsic '" + Name + "'");
-            return error(Info.second, "invalid intrinsic signature");
+            FunctionType *ExpFTy = nullptr;
+            if (!Intrinsic::isOverloaded(IID)) {
+              SmallVector<Type *, 4> OverloadTys;
+              ExpFTy =
+                  Intrinsic::getType(M->getContext(), IID, OverloadTys);
+            }
+            std::string Msg = "invalid intrinsic signature";
+            raw_string_ostream SS(Msg);
+            IntrinsicDiagnosticsProvider::queryParserMismatch(
+                Name, CB->getFunctionType(), ExpFTy, SS);
+            return error(Info.second, Msg);
           }
 
           U.set(TmpF);
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt
index ff362356fe65a..b9d4095654ed5 100644
--- a/llvm/lib/IR/CMakeLists.txt
+++ b/llvm/lib/IR/CMakeLists.txt
@@ -35,6 +35,8 @@ add_llvm_component_library(LLVMCore
   GVMaterializer.cpp
   Globals.cpp
   Intrinsics.cpp
+  IntrinsicDiagnostics.cpp
+  NVVMIntrinsicDiagnostics.cpp
   NVVMIntrinsicUtils.cpp
   IRBuilder.cpp
   IRPrintingPasses.cpp
diff --git a/llvm/lib/IR/IntrinsicDiagnostics.cpp b/llvm/lib/IR/IntrinsicDiagnostics.cpp
new file mode 100644
index 0000000000000..1d374dd4ebfe5
--- /dev/null
+++ b/llvm/lib/IR/IntrinsicDiagnostics.cpp
@@ -0,0 +1,51 @@
+//===-- IntrinsicDiagnostics.cpp - Intrinsic diagnostic hooks -------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/IntrinsicDiagnostics.h"
+#include "llvm/ADT/SmallVector.h"
+
+using namespace llvm;
+
+static SmallVector<IntrinsicDiagnosticsProvider *, 4> &getProviders() {
+  static SmallVector<IntrinsicDiagnosticsProvider *, 4> Providers;
+  return Providers;
+}
+
+void IntrinsicDiagnosticsProvider::registerProvider(
+    IntrinsicDiagnosticsProvider *P) {
+  getProviders().push_back(P);
+}
+
+void IntrinsicDiagnosticsProvider::querySignatureMismatch(
+    StringRef IntrName, FunctionType *DeclFTy, FunctionType *CallFTy,
+    raw_ostream &OS) {
+  for (auto *P : getProviders())
+    P->getSignatureMismatch(IntrName, DeclFTy, CallFTy, OS);
+}
+
+void IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(StringRef IntrName,
+                                                           FunctionType *IFTy,
+                                                           raw_ostream &OS) {
+  for (auto *P : getProviders())
+    P->getReturnTypeMismatch(IntrName, IFTy, OS);
+}
+
+void IntrinsicDiagnosticsProvider::queryArgTypeMismatch(StringRef IntrName,
+                                                        FunctionType *IFTy,
+                                                        raw_ostream &OS) {
+  for (auto *P : getProviders())
+    P->getArgTypeMismatch(IntrName, IFTy, OS);
+}
+
+void IntrinsicDiagnosticsProvider::queryParserMismatch(StringRef IntrName,
+                                                       FunctionType *CallFTy,
+                                                       FunctionType *ExpectedFTy,
+                                                       raw_ostream &OS) {
+  for (auto *P : getProviders())
+    P->getParserMismatch(IntrName, CallFTy, ExpectedFTy, OS);
+}
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
new file mode 100644
index 0000000000000..6b68cb889b8e4
--- /dev/null
+++ b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
@@ -0,0 +1,123 @@
+//===-- NVVMIntrinsicDiagnostics.cpp - Detailed NVVM diags ----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Registers a diagnostics provider that appends detailed information to error
+// messages for NVVM intrinsic signature mismatches.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/IntrinsicDiagnostics.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+static bool isNVVMIntrinsic(StringRef Name) {
+  return Name.starts_with("llvm.nvvm.");
+}
+
+/// Returns the canonical FunctionType for a non-overloaded intrinsic, or null.
+static FunctionType *getCanonicalType(StringRef Name, LLVMContext &Ctx) {
+  Intrinsic::ID ID = Intrinsic::lookupIntrinsicID(Name);
+  if (ID == Intrinsic::not_intrinsic || Intrinsic::isOverloaded(ID))
+    return nullptr;
+  SmallVector<Type *, 4> OverloadTys;
+  return Intrinsic::getType(Ctx, ID, OverloadTys);
+}
+
+namespace {
+
+class NVVMIntrinsicDiagnosticsProvider : public IntrinsicDiagnosticsProvider {
+public:
+  void getSignatureMismatch(StringRef Name, FunctionType *DeclFTy,
+                            FunctionType *CallFTy,
+                            raw_ostream &OS) const override {
+    if (!isNVVMIntrinsic(Name))
+      return;
+    if (DeclFTy->getReturnType() != CallFTy->getReturnType()) {
+      OS << "\nreturn type mismatch (expected ";
+      DeclFTy->getReturnType()->print(OS);
+      OS << ", got ";
+      CallFTy->getReturnType()->print(OS);
+      OS << ")";
+    } else if (DeclFTy->getNumParams() != CallFTy->getNumParams()) {
+      OS << "\nwrong number of arguments (expected " << DeclFTy->getNumParams()
+         << ", got " << CallFTy->getNumParams()
+         << "), expected signature: ";
+      DeclFTy->print(OS);
+      OS << ", got signature: ";
+      CallFTy->print(OS);
+    } else {
+      for (unsigned I = 0, E = DeclFTy->getNumParams(); I < E; ++I) {
+        if (DeclFTy->getParamType(I) != CallFTy->getParamType(I)) {
+          OS << "\nargument " << (I + 1) << " type mismatch (expected ";
+          DeclFTy->getParamType(I)->print(OS);
+          OS << ", got ";
+          CallFTy->getParamType(I)->print(OS);
+          OS << ")";
+          break;
+        }
+      }
+    }
+  }
+
+  void getReturnTypeMismatch(StringRef Name, FunctionType *IFTy,
+                             raw_ostream &OS) const override {
+    if (!isNVVMIntrinsic(Name))
+      return;
+    OS << "\ndeclared return type is '";
+    IFTy->getReturnType()->print(OS);
+    OS << "'";
+    if (FunctionType *ExpFTy = getCanonicalType(Name, IFTy->getContext())) {
+      OS << ", expected '";
+      ExpFTy->getReturnType()->print(OS);
+      OS << "' in canonical signature '";
+      ExpFTy->print(OS);
+      OS << "'";
+    }
+  }
+
+  void getArgTypeMismatch(StringRef Name, FunctionType *IFTy,
+                          raw_ostream &OS) const override {
+    if (!isNVVMIntrinsic(Name))
+      return;
+    OS << "\ndeclared signature is '";
+    IFTy->print(OS);
+    OS << "'";
+    if (FunctionType *ExpFTy = getCanonicalType(Name, IFTy->getContext())) {
+      OS << ", canonical signature is '";
+      ExpFTy->print(OS);
+      OS << "'";
+    }
+  }
+
+  void getParserMismatch(StringRef Name, FunctionType *CallFTy,
+                         FunctionType *ExpectedFTy,
+                         raw_ostream &OS) const override {
+    if (!isNVVMIntrinsic(Name))
+      return;
+    OS << "\nfor '" << Name << "': got ";
+    CallFTy->print(OS);
+    if (ExpectedFTy) {
+      OS << ", expected ";
+      ExpectedFTy->print(OS);
+    }
+  }
+};
+
+NVVMIntrinsicDiagnosticsProvider TheProvider;
+
+struct ProviderRegistrar {
+  ProviderRegistrar() {
+    IntrinsicDiagnosticsProvider::registerProvider(&TheProvider);
+  }
+};
+static ProviderRegistrar TheRegistrar;
+
+} // anonymous namespace
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index cf9131c66d6c3..6c348e600da5c 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -91,6 +91,7 @@
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicsAArch64.h"
@@ -3899,9 +3900,17 @@ void Verifier::visitCallBase(CallBase &Call) {
   Function *Callee =
       dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
   bool IsIntrinsic = Callee && Callee->isIntrinsic();
-  if (IsIntrinsic)
-    Check(Callee->getFunctionType() == FTy,
-          "Intrinsic called with incompatible signature", Call);
+  if (IsIntrinsic) {
+    FunctionType *DeclFTy = cast<FunctionType>(Callee->getValueType());
+    if (DeclFTy != FTy) {
+      std::string Msg = "Intrinsic called with incompatible signature";
+      raw_string_ostream SS(Msg);
+      IntrinsicDiagnosticsProvider::querySignatureMismatch(
+          Callee->getName(), DeclFTy, FTy, SS);
+      CheckFailed(Msg, Call);
+      return;
+    }
+  }
 
   // Verify if the calling convention of the callee is callable.
   Check(isCallableCC(Call.getCallingConv()),
@@ -5898,10 +5907,22 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   SmallVector<Type *, 4> ArgTys;
   Intrinsic::MatchIntrinsicTypesResult Res =
       Intrinsic::matchIntrinsicSignature(IFTy, TableRef, ArgTys);
-  Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet,
-        "Intrinsic has incorrect return type!", IF);
-  Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg,
-        "Intrinsic has incorrect argument type!", IF);
+  if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchRet) {
+    std::string Msg = "Intrinsic has incorrect return type!";
+    raw_string_ostream SS(Msg);
+    IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(
+        IF->getName(), IFTy, SS);
+    CheckFailed(Msg, IF);
+    return;
+  }
+  if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchArg) {
+    std::string Msg = "Intrinsic has incorrect argument type!";
+    raw_string_ostream SS(Msg);
+    IntrinsicDiagnosticsProvider::queryArgTypeMismatch(
+        IF->getName(), IFTy, SS);
+    CheckFailed(Msg, IF);
+    return;
+  }
 
   // Verify if the intrinsic call matches the vararg property.
   if (IsVarArg)
diff --git a/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll b/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
new file mode 100644
index 0000000000000..f91e51beb4bf3
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
@@ -0,0 +1,69 @@
+; RUN: split-file %s %t
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/main.ll 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-ret.ll 2>&1 | FileCheck %s --check-prefix=PARSER-RET
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-arg.ll 2>&1 | FileCheck %s --check-prefix=PARSER-ARG
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-count.ll 2>&1 | FileCheck %s --check-prefix=PARSER-COUNT
+
+; CHECK: Intrinsic has incorrect return type!
+; CHECK-NEXT: declared return type is 'i16', expected 'i32' in canonical signature 'i32 (i32, i32, i32)'
+; CHECK: Intrinsic called with incompatible signature
+; CHECK-NEXT: argument 3 type mismatch (expected i32, got i16)
+; CHECK: Intrinsic called with incompatible signature
+; CHECK-NEXT: wrong number of arguments (expected 3, got 4), expected signature: i64 (i64, i64, i64), got signature: i64 (i64, i64, i64, i64)
+
+; PARSER-RET: invalid intrinsic signature
+; PARSER-RET-NEXT: for 'llvm.nvvm.sad.i': got i16 (i32, i32, i32), expected i32 (i32, i32, i32)
+
+; PARSER-ARG: invalid intrinsic signature
+; PARSER-ARG-NEXT: for 'llvm.nvvm.sad.ui': got i32 (i32, i32, i16), expected i32 (i32, i32, i32)
+
+; PARSER-COUNT: invalid intrinsic signature
+; PARSER-COUNT-NEXT: for 'llvm.nvvm.sad.ull': got i64 (i64, i64, i64, i64), expected i64 (i64, i64, i64)
+
+;--- main.ll
+
+; Invalid return type: @llvm.nvvm.sad.i declared with i16 return instead of i32.
+define i16 @test_bad_ret(i32 %x, i32 %y, i32 %z) {
+  %1 = call i16 @llvm.nvvm.sad.i(i32 %x, i32 %y, i32 %z)
+  ret i16 %1
+}
+
+; Invalid argument type: @llvm.nvvm.sad.ui called with i16 third arg instead of i32.
+define i32 @test_bad_arg(i32 %x, i32 %y, i16 %z) {
+  %1 = call i32 @llvm.nvvm.sad.ui(i32 %x, i32 %y, i16 %z)
+  ret i32 %1
+}
+
+; Invalid argument count: @llvm.nvvm.sad.ull called with 4 args instead of 3.
+define i64 @test_bad_arg_count(i64 %x, i64 %y, i64 %z, i64 %w) {
+  %1 = call i64 @llvm.nvvm.sad.ull(i64 %x, i64 %y, i64 %z, i64 %w)
+  ret i64 %1
+}
+
+declare i16 @llvm.nvvm.sad.i(i32, i32, i32)
+declare i32 @llvm.nvvm.sad.ui(i32, i32, i32)
+declare i64 @llvm.nvvm.sad.ull(i64, i64, i64)
+
+;--- parser-bad-ret.ll
+
+; Parser error: no declaration, intrinsic called with wrong return type.
+define i16 @test_parser_bad_ret(i32 %x, i32 %y, i32 %z) {
+  %1 = call i16 @llvm.nvvm.sad.i(i32 %x, i32 %y, i32 %z)
+  ret i16 %1
+}
+
+;--- parser-bad-arg.ll
+
+; Parser error: no declaration, intrinsic called with wrong argument type.
+define i32 @test_parser_bad_arg(i32 %x, i32 %y, i16 %z) {
+  %1 = call i32 @llvm.nvvm.sad.ui(i32 %x, i32 %y, i16 %z)
+  ret i32 %1
+}
+
+;--- parser-bad-count.ll
+
+; Parser error: no declaration, intrinsic called with wrong argument count.
+define i64 @test_parser_bad_count(i64 %x, i64 %y, i64 %z, i64 %w) {
+  %1 = call i64 @llvm.nvvm.sad.ull(i64 %x, i64 %y, i64 %z, i64 %w)
+  ret i64 %1
+}

>From 9e433a1f68f484c9c8ce6523bf642be7534b9cb8 Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Tue, 10 Mar 2026 14:16:42 +0100
Subject: [PATCH 2/7] [LLVM] Fix code formatting issues

---
 llvm/lib/AsmParser/LLParser.cpp          |  3 +--
 llvm/lib/IR/IntrinsicDiagnostics.cpp     | 14 +++++++-------
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp |  3 +--
 llvm/lib/IR/Verifier.cpp                 | 11 +++++------
 4 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 661694974986f..287ec9213a900 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -358,8 +358,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
             FunctionType *ExpFTy = nullptr;
             if (!Intrinsic::isOverloaded(IID)) {
               SmallVector<Type *, 4> OverloadTys;
-              ExpFTy =
-                  Intrinsic::getType(M->getContext(), IID, OverloadTys);
+              ExpFTy = Intrinsic::getType(M->getContext(), IID, OverloadTys);
             }
             std::string Msg = "invalid intrinsic signature";
             raw_string_ostream SS(Msg);
diff --git a/llvm/lib/IR/IntrinsicDiagnostics.cpp b/llvm/lib/IR/IntrinsicDiagnostics.cpp
index 1d374dd4ebfe5..f776e5e2bba15 100644
--- a/llvm/lib/IR/IntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/IntrinsicDiagnostics.cpp
@@ -21,9 +21,10 @@ void IntrinsicDiagnosticsProvider::registerProvider(
   getProviders().push_back(P);
 }
 
-void IntrinsicDiagnosticsProvider::querySignatureMismatch(
-    StringRef IntrName, FunctionType *DeclFTy, FunctionType *CallFTy,
-    raw_ostream &OS) {
+void IntrinsicDiagnosticsProvider::querySignatureMismatch(StringRef IntrName,
+                                                          FunctionType *DeclFTy,
+                                                          FunctionType *CallFTy,
+                                                          raw_ostream &OS) {
   for (auto *P : getProviders())
     P->getSignatureMismatch(IntrName, DeclFTy, CallFTy, OS);
 }
@@ -42,10 +43,9 @@ void IntrinsicDiagnosticsProvider::queryArgTypeMismatch(StringRef IntrName,
     P->getArgTypeMismatch(IntrName, IFTy, OS);
 }
 
-void IntrinsicDiagnosticsProvider::queryParserMismatch(StringRef IntrName,
-                                                       FunctionType *CallFTy,
-                                                       FunctionType *ExpectedFTy,
-                                                       raw_ostream &OS) {
+void IntrinsicDiagnosticsProvider::queryParserMismatch(
+    StringRef IntrName, FunctionType *CallFTy, FunctionType *ExpectedFTy,
+    raw_ostream &OS) {
   for (auto *P : getProviders())
     P->getParserMismatch(IntrName, CallFTy, ExpectedFTy, OS);
 }
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
index 6b68cb889b8e4..7d3a45ad6830c 100644
--- a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
@@ -48,8 +48,7 @@ class NVVMIntrinsicDiagnosticsProvider : public IntrinsicDiagnosticsProvider {
       OS << ")";
     } else if (DeclFTy->getNumParams() != CallFTy->getNumParams()) {
       OS << "\nwrong number of arguments (expected " << DeclFTy->getNumParams()
-         << ", got " << CallFTy->getNumParams()
-         << "), expected signature: ";
+         << ", got " << CallFTy->getNumParams() << "), expected signature: ";
       DeclFTy->print(OS);
       OS << ", got signature: ";
       CallFTy->print(OS);
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 6c348e600da5c..5b0c2fa2be7a9 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3905,8 +3905,8 @@ void Verifier::visitCallBase(CallBase &Call) {
     if (DeclFTy != FTy) {
       std::string Msg = "Intrinsic called with incompatible signature";
       raw_string_ostream SS(Msg);
-      IntrinsicDiagnosticsProvider::querySignatureMismatch(
-          Callee->getName(), DeclFTy, FTy, SS);
+      IntrinsicDiagnosticsProvider::querySignatureMismatch(Callee->getName(),
+                                                           DeclFTy, FTy, SS);
       CheckFailed(Msg, Call);
       return;
     }
@@ -5910,16 +5910,15 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchRet) {
     std::string Msg = "Intrinsic has incorrect return type!";
     raw_string_ostream SS(Msg);
-    IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(
-        IF->getName(), IFTy, SS);
+    IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(IF->getName(), IFTy,
+                                                          SS);
     CheckFailed(Msg, IF);
     return;
   }
   if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchArg) {
     std::string Msg = "Intrinsic has incorrect argument type!";
     raw_string_ostream SS(Msg);
-    IntrinsicDiagnosticsProvider::queryArgTypeMismatch(
-        IF->getName(), IFTy, SS);
+    IntrinsicDiagnosticsProvider::queryArgTypeMismatch(IF->getName(), IFTy, SS);
     CheckFailed(Msg, IF);
     return;
   }

>From dfb5bce52e76dbefdce4cc58d940afd3c43ef2d3 Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Tue, 10 Mar 2026 21:20:49 +0100
Subject: [PATCH 3/7] [LLVM][NVVM][NVPTX] Fix NVVMIntrinsicDiagnosticsProvider
 not linked in static builds

---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h  | 4 ++++
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp     | 4 ++++
 llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
index 31fd31818bcee..857e837463069 100644
--- a/llvm/include/llvm/IR/IntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -67,6 +67,10 @@ class IntrinsicDiagnosticsProvider {
                                   FunctionType *ExpectedFTy, raw_ostream &OS);
 };
 
+/// Force-links the NVVM intrinsic diagnostics provider when building with
+/// static libraries.  Call from \c LLVMInitializeNVPTXTarget.
+LLVM_ABI void linkNVVMIntrinsicDiagnostics();
+
 } // namespace llvm
 
 #endif // LLVM_IR_INTRINSICDIAGNOSTICS_H
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
index 7d3a45ad6830c..7534ae9226a2e 100644
--- a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
@@ -120,3 +120,7 @@ struct ProviderRegistrar {
 static ProviderRegistrar TheRegistrar;
 
 } // anonymous namespace
+
+// Provide a hook to ensure the containing object file is linked when using
+// static libraries.  Call this from the NVPTX target initializer.
+void llvm::linkNVVMIntrinsicDiagnostics() {}
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
index 10e746c502c09..515683e79c7c0 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Pass.h"
@@ -100,6 +101,9 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTarget() {
   RegisterTargetMachine<NVPTXTargetMachine32> X(getTheNVPTXTarget32());
   RegisterTargetMachine<NVPTXTargetMachine64> Y(getTheNVPTXTarget64());
 
+  // Ensure the NVVM intrinsic diagnostics provider is linked in.
+  linkNVVMIntrinsicDiagnostics();
+
   PassRegistry &PR = *PassRegistry::getPassRegistry();
   // FIXME: This pass is really intended to be invoked during IR optimization,
   // but it's very NVPTX-specific.

>From 23c257911f8026a9334dfe072f462541df662e2a Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Wed, 11 Mar 2026 07:50:40 +0100
Subject: [PATCH 4/7] [NVVM] Move linkNVVMIntrinsicDiagnostics() to its own
 header

---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h   |  4 ---
 .../llvm/IR/NVVMIntrinsicDiagnostics.h        | 28 +++++++++++++++++++
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp      |  1 +
 llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp  |  2 +-
 4 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
index 857e837463069..31fd31818bcee 100644
--- a/llvm/include/llvm/IR/IntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -67,10 +67,6 @@ class IntrinsicDiagnosticsProvider {
                                   FunctionType *ExpectedFTy, raw_ostream &OS);
 };
 
-/// Force-links the NVVM intrinsic diagnostics provider when building with
-/// static libraries.  Call from \c LLVMInitializeNVPTXTarget.
-LLVM_ABI void linkNVVMIntrinsicDiagnostics();
-
 } // namespace llvm
 
 #endif // LLVM_IR_INTRINSICDIAGNOSTICS_H
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h b/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
new file mode 100644
index 0000000000000..b77a777e8a341
--- /dev/null
+++ b/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
@@ -0,0 +1,28 @@
+//===- NVVMIntrinsicDiagnostics.h - NVVM diagnostic provider ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Declares linkNVVMIntrinsicDiagnostics(), which must be called from
+// LLVMInitializeNVPTXTarget() to ensure the NVVM diagnostics provider object
+// file is linked in when building with static libraries.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
+#define LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
+
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+
+/// Force-links the NVVM intrinsic diagnostics provider when building with
+/// static libraries.  Call from \c LLVMInitializeNVPTXTarget.
+LLVM_ABI void linkNVVMIntrinsicDiagnostics();
+
+} // namespace llvm
+
+#endif // LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
index 7534ae9226a2e..34d4950655c84 100644
--- a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/IR/NVVMIntrinsicDiagnostics.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/Intrinsics.h"
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
index 515683e79c7c0..64288f9b23036 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -25,8 +25,8 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
-#include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
+#include "llvm/IR/NVVMIntrinsicDiagnostics.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Pass.h"
 #include "llvm/Passes/PassBuilder.h"

>From 9d33836a76eb9dc34b3a54648294885bcf936668 Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Wed, 11 Mar 2026 19:36:33 +0100
Subject: [PATCH 5/7] [LLVM] Remove filename from file headers per the latest
 LLVM CS

---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h     | 2 +-
 llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h | 2 +-
 llvm/lib/IR/IntrinsicDiagnostics.cpp            | 2 +-
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp        | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
index 31fd31818bcee..1bba9b4ef6786 100644
--- a/llvm/include/llvm/IR/IntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -1,4 +1,4 @@
-//===- IntrinsicDiagnostics.h - Intrinsic diagnostic hooks ------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h b/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
index b77a777e8a341..d9e20b72e80cb 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
@@ -1,4 +1,4 @@
-//===- NVVMIntrinsicDiagnostics.h - NVVM diagnostic provider ----*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/lib/IR/IntrinsicDiagnostics.cpp b/llvm/lib/IR/IntrinsicDiagnostics.cpp
index f776e5e2bba15..09127db8379ac 100644
--- a/llvm/lib/IR/IntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/IntrinsicDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===-- IntrinsicDiagnostics.cpp - Intrinsic diagnostic hooks -------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
index 34d4950655c84..31f420ddb2ca7 100644
--- a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===-- NVVMIntrinsicDiagnostics.cpp - Detailed NVVM diags ----------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

>From 2ef0bf218f9a27e166ed534bd9e6a5d0b4e61ed4 Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Fri, 13 Mar 2026 08:00:26 +0100
Subject: [PATCH 6/7] [LLVM][NVVM] Simplify IntrinsicDiagnosticsProvider

Replace the virtual base class + registration mechanism with a simple
static utility class whose query methods directly format the canonical
type information for any non-overloaded intrinsic.
---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h   |  68 ++++------
 .../llvm/IR/NVVMIntrinsicDiagnostics.h        |  28 ----
 llvm/lib/AsmParser/LLParser.cpp               |  13 +-
 llvm/lib/IR/CMakeLists.txt                    |   1 -
 llvm/lib/IR/IntrinsicDiagnostics.cpp          |  54 +++++---
 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp      | 127 ------------------
 llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp  |   4 -
 .../test/CodeGen/NVPTX/sad-intrins-invalid.ll |   9 +-
 8 files changed, 75 insertions(+), 229 deletions(-)
 delete mode 100644 llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
 delete mode 100644 llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
index 1bba9b4ef6786..b1ec02879ba82 100644
--- a/llvm/include/llvm/IR/IntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -6,10 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Defines IntrinsicDiagnosticsProvider, a virtual base class that targets
-// can subclass to append extra detail lines to intrinsic signature mismatch
-// diagnostics.  The default implementations are no-ops, leaving the standard
-// upstream message unchanged.
+// Defines IntrinsicDiagnosticsProvider, a utility class with static methods
+// that append detail lines to intrinsic signature mismatch diagnostics.
 //
 //===----------------------------------------------------------------------===//
 
@@ -17,54 +15,38 @@
 #define LLVM_IR_INTRINSICDIAGNOSTICS_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
 
 namespace llvm {
 class FunctionType;
 class raw_ostream;
 
-/// Interface for appending target-specific detail lines to diagnostics emitted
-/// when an intrinsic is called or declared with an incorrect signature.
-///
-/// Subclasses are registered via \c registerProvider.  At diagnostic emission
-/// time each registered provider may write additional lines to the output
-/// stream; the standard upstream message is always emitted first by the caller.
+/// Utility class that appends detail lines to diagnostics emitted when an
+/// intrinsic is called or declared with an incorrect signature.
 class IntrinsicDiagnosticsProvider {
 public:
-  virtual ~IntrinsicDiagnosticsProvider() = default;
-
-  /// Optionally appends detail for a call-site signature mismatch.
-  virtual void getSignatureMismatch(StringRef IntrName, FunctionType *DeclFTy,
-                                    FunctionType *CallFTy,
-                                    raw_ostream &OS) const {}
-
-  /// Optionally appends detail for a verifier return-type mismatch.
-  virtual void getReturnTypeMismatch(StringRef IntrName, FunctionType *IFTy,
-                                     raw_ostream &OS) const {}
-
-  /// Optionally appends detail for a verifier argument-type mismatch.
-  virtual void getArgTypeMismatch(StringRef IntrName, FunctionType *IFTy,
-                                  raw_ostream &OS) const {}
-
-  /// Optionally appends detail for a parser-level signature mismatch.
+  /// Appends detail for a call-site signature mismatch.
+  LLVM_ABI static void querySignatureMismatch(StringRef IntrName,
+                                              FunctionType *DeclFTy,
+                                              FunctionType *CallFTy,
+                                              raw_ostream &OS);
+
+  /// Appends detail for a verifier return-type mismatch.
+  LLVM_ABI static void queryReturnTypeMismatch(StringRef IntrName,
+                                               FunctionType *IFTy,
+                                               raw_ostream &OS);
+
+  /// Appends detail for a verifier argument-type mismatch.
+  LLVM_ABI static void
+  queryArgTypeMismatch(StringRef IntrName, FunctionType *IFTy, raw_ostream &OS);
+
+  /// Appends detail for a parser-level signature mismatch.
   /// \p ExpectedFTy is the canonical intrinsic type, or null for overloaded
   /// intrinsics.
-  virtual void getParserMismatch(StringRef IntrName, FunctionType *CallFTy,
-                                 FunctionType *ExpectedFTy,
-                                 raw_ostream &OS) const {}
-
-  /// Registers \p P as a diagnostics provider.  Does not take ownership;
-  /// \p P must outlive all diagnostic queries.
-  static void registerProvider(IntrinsicDiagnosticsProvider *P);
-
-  /// Asks all registered providers to append detail to \p OS.
-  static void querySignatureMismatch(StringRef IntrName, FunctionType *DeclFTy,
-                                     FunctionType *CallFTy, raw_ostream &OS);
-  static void queryReturnTypeMismatch(StringRef IntrName, FunctionType *IFTy,
-                                      raw_ostream &OS);
-  static void queryArgTypeMismatch(StringRef IntrName, FunctionType *IFTy,
-                                   raw_ostream &OS);
-  static void queryParserMismatch(StringRef IntrName, FunctionType *CallFTy,
-                                  FunctionType *ExpectedFTy, raw_ostream &OS);
+  LLVM_ABI static void queryParserMismatch(StringRef IntrName,
+                                           FunctionType *CallFTy,
+                                           FunctionType *ExpectedFTy,
+                                           raw_ostream &OS);
 };
 
 } // namespace llvm
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h b/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
deleted file mode 100644
index d9e20b72e80cb..0000000000000
--- a/llvm/include/llvm/IR/NVVMIntrinsicDiagnostics.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Declares linkNVVMIntrinsicDiagnostics(), which must be called from
-// LLVMInitializeNVPTXTarget() to ensure the NVVM diagnostics provider object
-// file is linked in when building with static libraries.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
-#define LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
-
-#include "llvm/Support/Compiler.h"
-
-namespace llvm {
-
-/// Force-links the NVVM intrinsic diagnostics provider when building with
-/// static libraries.  Call from \c LLVMInitializeNVPTXTarget.
-LLVM_ABI void linkNVVMIntrinsicDiagnostics();
-
-} // namespace llvm
-
-#endif // LLVM_IR_NVVMINTRINSICDIAGNOSTICS_H
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 287ec9213a900..dcfb667246372 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -356,14 +356,15 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
             if (IID == Intrinsic::not_intrinsic)
               return error(Info.second, "unknown intrinsic '" + Name + "'");
             FunctionType *ExpFTy = nullptr;
-            if (!Intrinsic::isOverloaded(IID)) {
-              SmallVector<Type *, 4> OverloadTys;
-              ExpFTy = Intrinsic::getType(M->getContext(), IID, OverloadTys);
-            }
-            std::string Msg = "invalid intrinsic signature";
-            raw_string_ostream SS(Msg);
+            if (!Intrinsic::isOverloaded(IID))
+              ExpFTy = Intrinsic::getType(M->getContext(), IID);
+            std::string Detail;
+            raw_string_ostream SS(Detail);
             IntrinsicDiagnosticsProvider::queryParserMismatch(
                 Name, CB->getFunctionType(), ExpFTy, SS);
+            std::string Msg = "invalid intrinsic signature";
+            if (!Detail.empty())
+              Msg += "\n" + Detail;
             return error(Info.second, Msg);
           }
 
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt
index b9d4095654ed5..0fdefd52a66f8 100644
--- a/llvm/lib/IR/CMakeLists.txt
+++ b/llvm/lib/IR/CMakeLists.txt
@@ -36,7 +36,6 @@ add_llvm_component_library(LLVMCore
   Globals.cpp
   Intrinsics.cpp
   IntrinsicDiagnostics.cpp
-  NVVMIntrinsicDiagnostics.cpp
   NVVMIntrinsicUtils.cpp
   IRBuilder.cpp
   IRPrintingPasses.cpp
diff --git a/llvm/lib/IR/IntrinsicDiagnostics.cpp b/llvm/lib/IR/IntrinsicDiagnostics.cpp
index 09127db8379ac..38cc8aa680694 100644
--- a/llvm/lib/IR/IntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/IntrinsicDiagnostics.cpp
@@ -7,45 +7,65 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/IntrinsicDiagnostics.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
-static SmallVector<IntrinsicDiagnosticsProvider *, 4> &getProviders() {
-  static SmallVector<IntrinsicDiagnosticsProvider *, 4> Providers;
-  return Providers;
-}
-
-void IntrinsicDiagnosticsProvider::registerProvider(
-    IntrinsicDiagnosticsProvider *P) {
-  getProviders().push_back(P);
+/// Returns the canonical FunctionType for a non-overloaded intrinsic, or null.
+static FunctionType *getCanonicalType(StringRef Name, LLVMContext &Ctx) {
+  Intrinsic::ID ID = Intrinsic::lookupIntrinsicID(Name);
+  if (ID == Intrinsic::not_intrinsic || Intrinsic::isOverloaded(ID))
+    return nullptr;
+  return Intrinsic::getType(Ctx, ID);
 }
 
 void IntrinsicDiagnosticsProvider::querySignatureMismatch(StringRef IntrName,
                                                           FunctionType *DeclFTy,
                                                           FunctionType *CallFTy,
                                                           raw_ostream &OS) {
-  for (auto *P : getProviders())
-    P->getSignatureMismatch(IntrName, DeclFTy, CallFTy, OS);
+  OS << ": expected signature: ";
+  DeclFTy->print(OS);
+  OS << ", got: ";
+  CallFTy->print(OS);
 }
 
 void IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(StringRef IntrName,
                                                            FunctionType *IFTy,
                                                            raw_ostream &OS) {
-  for (auto *P : getProviders())
-    P->getReturnTypeMismatch(IntrName, IFTy, OS);
+  OS << " declared return type is '";
+  IFTy->getReturnType()->print(OS);
+  OS << "'";
+  if (FunctionType *ExpFTy = getCanonicalType(IntrName, IFTy->getContext())) {
+    OS << ", expected '";
+    ExpFTy->getReturnType()->print(OS);
+    OS << "' in canonical signature '";
+    ExpFTy->print(OS);
+    OS << "'";
+  }
 }
 
 void IntrinsicDiagnosticsProvider::queryArgTypeMismatch(StringRef IntrName,
                                                         FunctionType *IFTy,
                                                         raw_ostream &OS) {
-  for (auto *P : getProviders())
-    P->getArgTypeMismatch(IntrName, IFTy, OS);
+  OS << " declared signature is '";
+  IFTy->print(OS);
+  OS << "'";
+  if (FunctionType *ExpFTy = getCanonicalType(IntrName, IFTy->getContext())) {
+    OS << ", canonical signature is '";
+    ExpFTy->print(OS);
+    OS << "'";
+  }
 }
 
 void IntrinsicDiagnosticsProvider::queryParserMismatch(
     StringRef IntrName, FunctionType *CallFTy, FunctionType *ExpectedFTy,
     raw_ostream &OS) {
-  for (auto *P : getProviders())
-    P->getParserMismatch(IntrName, CallFTy, ExpectedFTy, OS);
+  OS << "for '" << IntrName << "': got ";
+  CallFTy->print(OS);
+  if (ExpectedFTy) {
+    OS << ", expected ";
+    ExpectedFTy->print(OS);
+  }
 }
diff --git a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp b/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
deleted file mode 100644
index 31f420ddb2ca7..0000000000000
--- a/llvm/lib/IR/NVVMIntrinsicDiagnostics.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Registers a diagnostics provider that appends detailed information to error
-// messages for NVVM intrinsic signature mismatches.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/IR/NVVMIntrinsicDiagnostics.h"
-#include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/IntrinsicDiagnostics.h"
-#include "llvm/IR/Intrinsics.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-
-static bool isNVVMIntrinsic(StringRef Name) {
-  return Name.starts_with("llvm.nvvm.");
-}
-
-/// Returns the canonical FunctionType for a non-overloaded intrinsic, or null.
-static FunctionType *getCanonicalType(StringRef Name, LLVMContext &Ctx) {
-  Intrinsic::ID ID = Intrinsic::lookupIntrinsicID(Name);
-  if (ID == Intrinsic::not_intrinsic || Intrinsic::isOverloaded(ID))
-    return nullptr;
-  SmallVector<Type *, 4> OverloadTys;
-  return Intrinsic::getType(Ctx, ID, OverloadTys);
-}
-
-namespace {
-
-class NVVMIntrinsicDiagnosticsProvider : public IntrinsicDiagnosticsProvider {
-public:
-  void getSignatureMismatch(StringRef Name, FunctionType *DeclFTy,
-                            FunctionType *CallFTy,
-                            raw_ostream &OS) const override {
-    if (!isNVVMIntrinsic(Name))
-      return;
-    if (DeclFTy->getReturnType() != CallFTy->getReturnType()) {
-      OS << "\nreturn type mismatch (expected ";
-      DeclFTy->getReturnType()->print(OS);
-      OS << ", got ";
-      CallFTy->getReturnType()->print(OS);
-      OS << ")";
-    } else if (DeclFTy->getNumParams() != CallFTy->getNumParams()) {
-      OS << "\nwrong number of arguments (expected " << DeclFTy->getNumParams()
-         << ", got " << CallFTy->getNumParams() << "), expected signature: ";
-      DeclFTy->print(OS);
-      OS << ", got signature: ";
-      CallFTy->print(OS);
-    } else {
-      for (unsigned I = 0, E = DeclFTy->getNumParams(); I < E; ++I) {
-        if (DeclFTy->getParamType(I) != CallFTy->getParamType(I)) {
-          OS << "\nargument " << (I + 1) << " type mismatch (expected ";
-          DeclFTy->getParamType(I)->print(OS);
-          OS << ", got ";
-          CallFTy->getParamType(I)->print(OS);
-          OS << ")";
-          break;
-        }
-      }
-    }
-  }
-
-  void getReturnTypeMismatch(StringRef Name, FunctionType *IFTy,
-                             raw_ostream &OS) const override {
-    if (!isNVVMIntrinsic(Name))
-      return;
-    OS << "\ndeclared return type is '";
-    IFTy->getReturnType()->print(OS);
-    OS << "'";
-    if (FunctionType *ExpFTy = getCanonicalType(Name, IFTy->getContext())) {
-      OS << ", expected '";
-      ExpFTy->getReturnType()->print(OS);
-      OS << "' in canonical signature '";
-      ExpFTy->print(OS);
-      OS << "'";
-    }
-  }
-
-  void getArgTypeMismatch(StringRef Name, FunctionType *IFTy,
-                          raw_ostream &OS) const override {
-    if (!isNVVMIntrinsic(Name))
-      return;
-    OS << "\ndeclared signature is '";
-    IFTy->print(OS);
-    OS << "'";
-    if (FunctionType *ExpFTy = getCanonicalType(Name, IFTy->getContext())) {
-      OS << ", canonical signature is '";
-      ExpFTy->print(OS);
-      OS << "'";
-    }
-  }
-
-  void getParserMismatch(StringRef Name, FunctionType *CallFTy,
-                         FunctionType *ExpectedFTy,
-                         raw_ostream &OS) const override {
-    if (!isNVVMIntrinsic(Name))
-      return;
-    OS << "\nfor '" << Name << "': got ";
-    CallFTy->print(OS);
-    if (ExpectedFTy) {
-      OS << ", expected ";
-      ExpectedFTy->print(OS);
-    }
-  }
-};
-
-NVVMIntrinsicDiagnosticsProvider TheProvider;
-
-struct ProviderRegistrar {
-  ProviderRegistrar() {
-    IntrinsicDiagnosticsProvider::registerProvider(&TheProvider);
-  }
-};
-static ProviderRegistrar TheRegistrar;
-
-} // anonymous namespace
-
-// Provide a hook to ensure the containing object file is linked when using
-// static libraries.  Call this from the NVPTX target initializer.
-void llvm::linkNVVMIntrinsicDiagnostics() {}
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
index 64288f9b23036..10e746c502c09 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -26,7 +26,6 @@
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
-#include "llvm/IR/NVVMIntrinsicDiagnostics.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Pass.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -101,9 +100,6 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTarget() {
   RegisterTargetMachine<NVPTXTargetMachine32> X(getTheNVPTXTarget32());
   RegisterTargetMachine<NVPTXTargetMachine64> Y(getTheNVPTXTarget64());
 
-  // Ensure the NVVM intrinsic diagnostics provider is linked in.
-  linkNVVMIntrinsicDiagnostics();
-
   PassRegistry &PR = *PassRegistry::getPassRegistry();
   // FIXME: This pass is really intended to be invoked during IR optimization,
   // but it's very NVPTX-specific.
diff --git a/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll b/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
index f91e51beb4bf3..31128597bc7f4 100644
--- a/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
+++ b/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
@@ -5,11 +5,14 @@
 ; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-count.ll 2>&1 | FileCheck %s --check-prefix=PARSER-COUNT
 
 ; CHECK: Intrinsic has incorrect return type!
-; CHECK-NEXT: declared return type is 'i16', expected 'i32' in canonical signature 'i32 (i32, i32, i32)'
+; CHECK-SAME: declared return type is 'i16', expected 'i32' in canonical signature 'i32 (i32, i32, i32)'
+; CHECK-NEXT: @llvm.nvvm.sad.i
 ; CHECK: Intrinsic called with incompatible signature
-; CHECK-NEXT: argument 3 type mismatch (expected i32, got i16)
+; CHECK-SAME: expected signature: i32 (i32, i32, i32), got: i32 (i32, i32, i16)
+; CHECK-NEXT: @llvm.nvvm.sad.ui
 ; CHECK: Intrinsic called with incompatible signature
-; CHECK-NEXT: wrong number of arguments (expected 3, got 4), expected signature: i64 (i64, i64, i64), got signature: i64 (i64, i64, i64, i64)
+; CHECK-SAME: expected signature: i64 (i64, i64, i64), got: i64 (i64, i64, i64, i64)
+; CHECK-NEXT: @llvm.nvvm.sad.ull
 
 ; PARSER-RET: invalid intrinsic signature
 ; PARSER-RET-NEXT: for 'llvm.nvvm.sad.i': got i16 (i32, i32, i32), expected i32 (i32, i32, i32)

>From ab300d500b1e3dda9c9b466ed75d613b7b3e892a Mon Sep 17 00:00:00 2001
From: Kirill Vedernikov <kvedernikov at nvidia.com>
Date: Mon, 16 Mar 2026 16:55:11 +0100
Subject: [PATCH 7/7] [LLVM][Verifier] Move intrinsic signature mismatch detail
 into getIntrinsicSignature

---
 llvm/include/llvm/IR/IntrinsicDiagnostics.h   | 13 +----
 llvm/include/llvm/IR/Intrinsics.h             |  9 +++-
 llvm/lib/IR/IntrinsicDiagnostics.cpp          | 37 --------------
 llvm/lib/IR/Intrinsics.cpp                    | 42 ++++++++++++++++
 llvm/lib/IR/Verifier.cpp                      | 15 +-----
 ...ntrins-invalid.ll => intrinsic-invalid.ll} | 48 +++++++++++++++++++
 6 files changed, 102 insertions(+), 62 deletions(-)
 rename llvm/test/CodeGen/NVPTX/{sad-intrins-invalid.ll => intrinsic-invalid.ll} (57%)

diff --git a/llvm/include/llvm/IR/IntrinsicDiagnostics.h b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
index b1ec02879ba82..b86a975619d72 100644
--- a/llvm/include/llvm/IR/IntrinsicDiagnostics.h
+++ b/llvm/include/llvm/IR/IntrinsicDiagnostics.h
@@ -21,8 +21,8 @@ namespace llvm {
 class FunctionType;
 class raw_ostream;
 
-/// Utility class that appends detail lines to diagnostics emitted when an
-/// intrinsic is called or declared with an incorrect signature.
+/// Utility class that formats detail for intrinsic signature mismatch
+/// diagnostics.
 class IntrinsicDiagnosticsProvider {
 public:
   /// Appends detail for a call-site signature mismatch.
@@ -31,15 +31,6 @@ class IntrinsicDiagnosticsProvider {
                                               FunctionType *CallFTy,
                                               raw_ostream &OS);
 
-  /// Appends detail for a verifier return-type mismatch.
-  LLVM_ABI static void queryReturnTypeMismatch(StringRef IntrName,
-                                               FunctionType *IFTy,
-                                               raw_ostream &OS);
-
-  /// Appends detail for a verifier argument-type mismatch.
-  LLVM_ABI static void
-  queryArgTypeMismatch(StringRef IntrName, FunctionType *IFTy, raw_ostream &OS);
-
   /// Appends detail for a parser-level signature mismatch.
   /// \p ExpectedFTy is the canonical intrinsic type, or null for overloaded
   /// intrinsics.
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index f25df4f42d418..970d8de648455 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -280,7 +280,7 @@ namespace Intrinsic {
   LLVM_ABI bool matchIntrinsicVarArg(bool isVarArg,
                                      ArrayRef<IITDescriptor> &Infos);
 
-  /// Gets the type arguments of an intrinsic call by matching type contraints
+  /// Gets the type arguments of an intrinsic call by matching type constraints
   /// specified by the .td file. The overloaded types are pushed into the
   /// OverloadTys vector.
   ///
@@ -293,6 +293,13 @@ namespace Intrinsic {
   LLVM_ABI bool getIntrinsicSignature(Function *F,
                                       SmallVectorImpl<Type *> &OverloadTys);
 
+  /// Returns a human-readable description of a signature mismatch for the
+  /// given intrinsic ID and function type. For non-overloaded intrinsics the
+  /// canonical signature is included; for overloaded intrinsics only the
+  /// declared signature is shown.
+  LLVM_ABI std::string getIntrinsicSignatureMismatch(Intrinsic::ID,
+                                                     FunctionType *FT);
+
   // Checks if the intrinsic name matches with its signature and if not
   // returns the declaration with the same signature and remangled name.
   // An existing GlobalValue with the wanted name but with a wrong prototype
diff --git a/llvm/lib/IR/IntrinsicDiagnostics.cpp b/llvm/lib/IR/IntrinsicDiagnostics.cpp
index 38cc8aa680694..93e1c8333a4bb 100644
--- a/llvm/lib/IR/IntrinsicDiagnostics.cpp
+++ b/llvm/lib/IR/IntrinsicDiagnostics.cpp
@@ -8,19 +8,10 @@
 
 #include "llvm/IR/IntrinsicDiagnostics.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Intrinsics.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
-/// Returns the canonical FunctionType for a non-overloaded intrinsic, or null.
-static FunctionType *getCanonicalType(StringRef Name, LLVMContext &Ctx) {
-  Intrinsic::ID ID = Intrinsic::lookupIntrinsicID(Name);
-  if (ID == Intrinsic::not_intrinsic || Intrinsic::isOverloaded(ID))
-    return nullptr;
-  return Intrinsic::getType(Ctx, ID);
-}
-
 void IntrinsicDiagnosticsProvider::querySignatureMismatch(StringRef IntrName,
                                                           FunctionType *DeclFTy,
                                                           FunctionType *CallFTy,
@@ -31,34 +22,6 @@ void IntrinsicDiagnosticsProvider::querySignatureMismatch(StringRef IntrName,
   CallFTy->print(OS);
 }
 
-void IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(StringRef IntrName,
-                                                           FunctionType *IFTy,
-                                                           raw_ostream &OS) {
-  OS << " declared return type is '";
-  IFTy->getReturnType()->print(OS);
-  OS << "'";
-  if (FunctionType *ExpFTy = getCanonicalType(IntrName, IFTy->getContext())) {
-    OS << ", expected '";
-    ExpFTy->getReturnType()->print(OS);
-    OS << "' in canonical signature '";
-    ExpFTy->print(OS);
-    OS << "'";
-  }
-}
-
-void IntrinsicDiagnosticsProvider::queryArgTypeMismatch(StringRef IntrName,
-                                                        FunctionType *IFTy,
-                                                        raw_ostream &OS) {
-  OS << " declared signature is '";
-  IFTy->print(OS);
-  OS << "'";
-  if (FunctionType *ExpFTy = getCanonicalType(IntrName, IFTy->getContext())) {
-    OS << ", canonical signature is '";
-    ExpFTy->print(OS);
-    OS << "'";
-  }
-}
-
 void IntrinsicDiagnosticsProvider::queryParserMismatch(
     StringRef IntrName, FunctionType *CallFTy, FunctionType *ExpectedFTy,
     raw_ostream &OS) {
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 0e01529bda711..bef3a011c1650 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringTable.h"
 #include "llvm/IR/ConstantRange.h"
+#include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IntrinsicsAArch64.h"
 #include "llvm/IR/IntrinsicsAMDGPU.h"
@@ -34,6 +35,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/NVVMIntrinsicUtils.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
@@ -1146,6 +1148,46 @@ bool Intrinsic::getIntrinsicSignature(Function *F,
                                OverloadTys);
 }
 
+std::string Intrinsic::getIntrinsicSignatureMismatch(Intrinsic::ID ID,
+                                                     FunctionType *FT) {
+  SmallVector<Intrinsic::IITDescriptor, 8> Table;
+  getIntrinsicInfoTableEntries(ID, Table);
+  ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
+
+  SmallVector<Type *, 4> ArgTys;
+  MatchIntrinsicTypesResult Res =
+      Intrinsic::matchIntrinsicSignature(FT, TableRef, ArgTys);
+
+  std::string Msg;
+  raw_string_ostream OS(Msg);
+  FunctionType *CanonFT =
+      isOverloaded(ID) ? nullptr : getType(FT->getContext(), ID);
+  if (Res == MatchIntrinsicTypes_NoMatchRet) {
+    OS << "Intrinsic has incorrect return type! declared return type is '";
+    FT->getReturnType()->print(OS);
+    OS << "'";
+    if (CanonFT) {
+      OS << ", expected '";
+      CanonFT->getReturnType()->print(OS);
+      OS << "' in canonical signature '";
+      CanonFT->print(OS);
+      OS << "'";
+    }
+  } else if (Res == MatchIntrinsicTypes_NoMatchArg) {
+    OS << "Intrinsic has incorrect argument type! declared signature is '";
+    FT->print(OS);
+    OS << "'";
+    if (CanonFT) {
+      OS << ", canonical signature is '";
+      CanonFT->print(OS);
+      OS << "'";
+    }
+  } else {
+    llvm_unreachable("unexpected MatchIntrinsicTypesResult");
+  }
+  return Msg;
+}
+
 std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
   SmallVector<Type *, 4> OverloadTys;
   if (!getIntrinsicSignature(F, OverloadTys))
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 5b0c2fa2be7a9..903ef7132c475 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5907,19 +5907,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   SmallVector<Type *, 4> ArgTys;
   Intrinsic::MatchIntrinsicTypesResult Res =
       Intrinsic::matchIntrinsicSignature(IFTy, TableRef, ArgTys);
-  if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchRet) {
-    std::string Msg = "Intrinsic has incorrect return type!";
-    raw_string_ostream SS(Msg);
-    IntrinsicDiagnosticsProvider::queryReturnTypeMismatch(IF->getName(), IFTy,
-                                                          SS);
-    CheckFailed(Msg, IF);
-    return;
-  }
-  if (Res == Intrinsic::MatchIntrinsicTypes_NoMatchArg) {
-    std::string Msg = "Intrinsic has incorrect argument type!";
-    raw_string_ostream SS(Msg);
-    IntrinsicDiagnosticsProvider::queryArgTypeMismatch(IF->getName(), IFTy, SS);
-    CheckFailed(Msg, IF);
+  if (Res != Intrinsic::MatchIntrinsicTypes_Match) {
+    CheckFailed(Intrinsic::getIntrinsicSignatureMismatch(ID, IFTy), IF);
     return;
   }
 
diff --git a/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll b/llvm/test/CodeGen/NVPTX/intrinsic-invalid.ll
similarity index 57%
rename from llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
rename to llvm/test/CodeGen/NVPTX/intrinsic-invalid.ll
index 31128597bc7f4..9bc041db695f2 100644
--- a/llvm/test/CodeGen/NVPTX/sad-intrins-invalid.ll
+++ b/llvm/test/CodeGen/NVPTX/intrinsic-invalid.ll
@@ -1,19 +1,37 @@
 ; RUN: split-file %s %t
 ; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/main.ll 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/fma-bad-call.ll 2>&1 | FileCheck %s --check-prefix=FMA-CALL
 ; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-ret.ll 2>&1 | FileCheck %s --check-prefix=PARSER-RET
 ; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-arg.ll 2>&1 | FileCheck %s --check-prefix=PARSER-ARG
 ; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-bad-count.ll 2>&1 | FileCheck %s --check-prefix=PARSER-COUNT
+; RUN: not llc -mtriple=nvptx64 -mcpu=sm_50 < %t/parser-fma-bad-arg.ll 2>&1 | FileCheck %s --check-prefix=PARSER-FMA-ARG
 
+; Non-overloaded intrinsic: wrong return type — canonical signature shown.
 ; CHECK: Intrinsic has incorrect return type!
 ; CHECK-SAME: declared return type is 'i16', expected 'i32' in canonical signature 'i32 (i32, i32, i32)'
 ; CHECK-NEXT: @llvm.nvvm.sad.i
+
+; Non-overloaded intrinsic: wrong call-site argument type.
 ; CHECK: Intrinsic called with incompatible signature
 ; CHECK-SAME: expected signature: i32 (i32, i32, i32), got: i32 (i32, i32, i16)
 ; CHECK-NEXT: @llvm.nvvm.sad.ui
+
+; Non-overloaded intrinsic: wrong call-site argument count.
 ; CHECK: Intrinsic called with incompatible signature
 ; CHECK-SAME: expected signature: i64 (i64, i64, i64), got: i64 (i64, i64, i64, i64)
 ; CHECK-NEXT: @llvm.nvvm.sad.ull
 
+; Overloaded intrinsic: wrong argument type in declaration — no canonical signature shown.
+; CHECK: Intrinsic has incorrect argument type!
+; CHECK-SAME: declared signature is 'float (float, float, double)'
+; CHECK-NOT: canonical signature
+; CHECK-NEXT: @llvm.fma.f32
+
+; Overloaded intrinsic: wrong call-site argument type — declared and actual signatures shown.
+; FMA-CALL: Intrinsic called with incompatible signature
+; FMA-CALL-SAME: expected signature: float (float, float, float), got: float (float, float, double)
+; FMA-CALL-NEXT: @llvm.fma.f32
+
 ; PARSER-RET: invalid intrinsic signature
 ; PARSER-RET-NEXT: for 'llvm.nvvm.sad.i': got i16 (i32, i32, i32), expected i32 (i32, i32, i32)
 
@@ -23,6 +41,10 @@
 ; PARSER-COUNT: invalid intrinsic signature
 ; PARSER-COUNT-NEXT: for 'llvm.nvvm.sad.ull': got i64 (i64, i64, i64, i64), expected i64 (i64, i64, i64)
 
+; Overloaded intrinsic: parser error — no expected signature shown.
+; PARSER-FMA-ARG: invalid intrinsic signature
+; PARSER-FMA-ARG-NEXT: for 'llvm.fma.f32': got float (float, float, double)
+
 ;--- main.ll
 
 ; Invalid return type: @llvm.nvvm.sad.i declared with i16 return instead of i32.
@@ -43,9 +65,26 @@ define i64 @test_bad_arg_count(i64 %x, i64 %y, i64 %z, i64 %w) {
   ret i64 %1
 }
 
+; Overloaded intrinsic: third argument declared as double instead of float.
+define float @test_overloaded_bad_arg(float %x, float %y, double %z) {
+  %1 = call float @llvm.fma.f32(float %x, float %y, double %z)
+  ret float %1
+}
+
 declare i16 @llvm.nvvm.sad.i(i32, i32, i32)
 declare i32 @llvm.nvvm.sad.ui(i32, i32, i32)
 declare i64 @llvm.nvvm.sad.ull(i64, i64, i64)
+declare float @llvm.fma.f32(float, float, double)
+
+;--- fma-bad-call.ll
+
+; Overloaded intrinsic: correct declaration, third argument wrong at call site.
+define float @test_overloaded_bad_call_arg(float %x, float %y, double %z) {
+  %1 = call float @llvm.fma.f32(float %x, float %y, double %z)
+  ret float %1
+}
+
+declare float @llvm.fma.f32(float, float, float)
 
 ;--- parser-bad-ret.ll
 
@@ -70,3 +109,12 @@ define i64 @test_parser_bad_count(i64 %x, i64 %y, i64 %z, i64 %w) {
   %1 = call i64 @llvm.nvvm.sad.ull(i64 %x, i64 %y, i64 %z, i64 %w)
   ret i64 %1
 }
+
+;--- parser-fma-bad-arg.ll
+
+; Parser error: no declaration, overloaded intrinsic called with wrong argument type.
+; Expected signature is not shown since the intrinsic is overloaded.
+define float @test_parser_fma_bad_arg(float %x, float %y, double %z) {
+  %1 = call float @llvm.fma.f32(float %x, float %y, double %z)
+  ret float %1
+}



More information about the llvm-commits mailing list