[llvm] [NFC][LLVM][AsmWriter] Print a comment for unknown intrinsics (PR #146726)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 08:29:45 PDT 2025


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

Unknown intrinsics are functions that begin with `llvm.` but are not an intrinsic that is recognized by LLVM. Add a comment before such functions in LLVM IR assembly to indicate that they are unknown intrinsics.

>From 17f8f2e0c43b75123ed0351ac26e42ef10b7f0ef Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 2 Jul 2025 08:26:01 -0700
Subject: [PATCH] [NFC][LLVM][AsmWriter] Print a comment for unknown intrinsics

Unknown intrinsics are functions that begin with `llvm.` but are
not an intrinsic that is recognized by LLVM. Add a comment before
such functions in LLVM IR assembly to indicate that they are
unknown intrinsics.
---
 llvm/lib/IR/AsmWriter.cpp       | 3 +++
 llvm/test/Feature/intrinsics.ll | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index af268b4fc6941..b21f4347f34d3 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -4129,6 +4129,9 @@ void AssemblyWriter::printFunction(const Function *F) {
       Out << "; Function Attrs: " << AttrStr << '\n';
   }
 
+  if (F->isIntrinsic() && F->getIntrinsicID() == Intrinsic::not_intrinsic)
+    Out << "; Unknown intrinsic\n";
+
   Machine.incorporateFunction(F);
 
   if (F->isDeclaration()) {
diff --git a/llvm/test/Feature/intrinsics.ll b/llvm/test/Feature/intrinsics.ll
index 49fed0981bd76..b6abc0fff6db7 100644
--- a/llvm/test/Feature/intrinsics.ll
+++ b/llvm/test/Feature/intrinsics.ll
@@ -3,8 +3,12 @@
 ; RUN: diff %t1.ll %t2.ll
 ; RUN: FileCheck %s < %t1.ll
 
+; CHECK: Unknown intrinsic
+; CHECK-NEXT: declare i1 @llvm.isunordered.f32(float, float)
 declare i1 @llvm.isunordered.f32(float, float)
 
+; CHECK: Unknown intrinsic
+; CHECK-NEXT: declare i1 @llvm.isunordered.f64(double, double)
 declare i1 @llvm.isunordered.f64(double, double)
 
 
@@ -60,7 +64,6 @@ define void @libm() {
 
 ; FIXME: test ALL the intrinsics in this file.
 
-; rdar://11542750
 ; CHECK: declare void @llvm.trap() #1
 declare void @llvm.trap()
 



More information about the llvm-commits mailing list