[llvm] [Attr] Add `noipa` function attribute (PR #203304)
J. Ryan Stinnett via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 07:00:12 PDT 2026
https://github.com/jryans updated https://github.com/llvm/llvm-project/pull/203304
>From 3063d323973126cbb760e657b236aec5cf28ace8 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Thu, 11 Jun 2026 15:06:51 +0100
Subject: [PATCH 01/23] [Attr] Add `noipa` function attribute
This adds a `noipa` function attribute to LLVM IR. This new attribute
disables any interprocedural analysis that inspects the definition of
the function. Setting this attribute is equivalent to moving the
function definition to a separate, optimizer-opaque, module.
Revival of https://reviews.llvm.org/D101011
Discussed in https://discourse.llvm.org/t/noipa-continues/74411
LLVM portion of https://github.com/llvm/llvm-project/issues/40819
---
llvm/docs/LangRef.rst | 5 +++++
llvm/include/llvm/Bitcode/LLVMBitCodes.h | 1 +
llvm/include/llvm/IR/Attributes.td | 3 +++
llvm/include/llvm/IR/GlobalValue.h | 10 +++++++---
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++
llvm/lib/IR/Globals.cpp | 7 +++++++
llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 12 ++++++------
llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
llvm/test/Bitcode/attributes.ll | 6 ++++++
llvm/unittests/IR/FunctionTest.cpp | 11 +++++++++++
llvm/utils/emacs/llvm-mode.el | 2 +-
llvm/utils/kate/llvm.xml | 1 +
llvm/utils/vim/syntax/llvm.vim | 1 +
llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml | 1 +
15 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index cf052513c5ef8..d2a1a32e2c6df 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2390,6 +2390,11 @@ For example:
This attribute indicates that the inliner should never inline this
function in any situation. This attribute may not be used together
with the ``alwaysinline`` attribute.
+``noipa``
+ Disables any interprocedural analysis that inspects the definition of this
+ function. Equivalent to moving this function definition to a separate,
+ optimizer-opaque, module. Any attributes on the function are still respected
+ (as they would be if they remained on a function declaration in this module).
``nomerge``
This attribute indicates that calls to this function should never be merged
during optimization. For example, it will prevent tail merging otherwise
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 95787c595dff7..5c2b681cc3d63 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -820,6 +820,7 @@ enum AttributeKindCodes {
ATTR_KIND_DENORMAL_FPENV = 106,
ATTR_KIND_NOOUTLINE = 107,
ATTR_KIND_FLATTEN = 108,
+ ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS = 109,
};
enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td
index 34032e341d85e..4e45100b54d38 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -218,6 +218,9 @@ def NoInline : EnumAttr<"noinline", IntersectPreserve, [FnAttr]>;
/// nooutline
def NoOutline : EnumAttr<"nooutline", IntersectPreserve, [FnAttr]>;
+/// Do not do interprocedural analysis or optimization including this function
+def NoIPA : EnumAttr<"noipa", IntersectPreserve, [FnAttr]>;
+
/// Function is called early and/or often, so lazy binding isn't worthwhile.
def NonLazyBind : EnumAttr<"nonlazybind", IntersectPreserve, [FnAttr]>;
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 83e695cdd27d9..59424f201be84 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -136,7 +136,7 @@ class GlobalValue : public Constant {
/// Returns true if the definition of this global may be replaced by a
/// differently optimized variant of the same source level function at link
/// time.
- bool mayBeDerefined() const {
+ bool mayBeDerefinedOrNoIPA() const {
switch (getLinkage()) {
case WeakODRLinkage:
case LinkOnceODRLinkage:
@@ -155,7 +155,7 @@ class GlobalValue : public Constant {
// nobuiltin due to attributes at call-sites. To avoid applying IPO based
// on nobuiltin semantics, treat such function definitions as maybe
// derefined.
- return isInterposable() || isNobuiltinFnDef();
+ return isInterposable() || isNobuiltinFnDef() || isNoipaFnDef();
}
llvm_unreachable("Fully covered switch above!");
@@ -165,6 +165,10 @@ class GlobalValue : public Constant {
/// attribute.
LLVM_ABI bool isNobuiltinFnDef() const;
+ /// Returns true if the global is a function definition with the noipa
+ /// attribute.
+ LLVM_ABI bool isNoipaFnDef() const;
+
protected:
/// The intrinsic ID for this subclass (which must be a Function).
///
@@ -490,7 +494,7 @@ class GlobalValue : public Constant {
/// visible variant is *a* correct implementation of the original source
/// function; it just isn't the *only* correct implementation.
bool isDefinitionExact() const {
- return !mayBeDerefined();
+ return !mayBeDerefinedOrNoIPA();
}
/// Return true if this global has an exact defintion.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 87ae36afb4e65..04a62dccea179 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2302,6 +2302,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::DenormalFPEnv;
case bitc::ATTR_KIND_NOOUTLINE:
return Attribute::NoOutline;
+ case bitc::ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS:
+ return Attribute::NoIPA;
}
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index f4857461ca58e..f8f5c6953f94a 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1008,6 +1008,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
return bitc::ATTR_KIND_DENORMAL_FPENV;
case Attribute::NoOutline:
return bitc::ATTR_KIND_NOOUTLINE;
+ case Attribute::NoIPA:
+ return bitc::ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS;
case Attribute::EndAttrKinds:
llvm_unreachable("Can not encode end-attribute kinds marker.");
case Attribute::None:
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 805595a80a054..422517dd05843 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -334,6 +334,13 @@ bool GlobalValue::isNobuiltinFnDef() const {
return F->hasFnAttribute(Attribute::NoBuiltin);
}
+bool GlobalValue::isNoipaFnDef() const {
+ const Function *F = dyn_cast<Function>(this);
+ if (!F || F->empty())
+ return false;
+ return F->hasFnAttribute(Attribute::NoIPA);
+}
+
bool GlobalValue::isDeclaration() const {
// Globals are definitions if they have an initializer.
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 467fab519d32a..786ce066132e4 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -976,7 +976,7 @@ static void addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes,
for (Function *F : SCCNodes) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F->hasExactDefinition())
continue;
@@ -1250,7 +1250,7 @@ static void addArgumentAttrs(const SCCNodeSet &SCCNodes,
for (Function *F : SCCNodes) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F->hasExactDefinition())
continue;
@@ -1503,7 +1503,7 @@ static void addNoAliasAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F->hasExactDefinition())
return;
@@ -1620,7 +1620,7 @@ static void addNonNullAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F->hasExactDefinition())
return;
@@ -1674,7 +1674,7 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F->hasExactDefinition())
return;
@@ -2154,7 +2154,7 @@ static void addColdAttrs(const SCCNodeSet &SCCNodes,
static bool functionWillReturn(const Function &F) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefined.
+ // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
if (!F.hasExactDefinition())
return false;
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 7ffa99878cf74..39631d0c68f07 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -983,6 +983,7 @@ Function *CodeExtractor::constructFunctionDeclaration(
case Attribute::NoFree:
case Attribute::NoImplicitFloat:
case Attribute::NoInline:
+ case Attribute::NoIPA:
case Attribute::NoOutline:
case Attribute::NonLazyBind:
case Attribute::NoRedZone:
diff --git a/llvm/test/Bitcode/attributes.ll b/llvm/test/Bitcode/attributes.ll
index 21712fae7eecd..f696f2dd12323 100644
--- a/llvm/test/Bitcode/attributes.ll
+++ b/llvm/test/Bitcode/attributes.ll
@@ -592,6 +592,11 @@ define void @dead_on_return_sized(ptr dead_on_return(4) %p) {
ret void
}
+; CHECK: define void @noipa() [[NOIPA:#[0-9]+]]
+define void @noipa() noipa {
+ ret void
+}
+
; CHECK: attributes #0 = { noreturn }
; CHECK: attributes #1 = { nounwind }
; CHECK: attributes #2 = { memory(none) }
@@ -654,4 +659,5 @@ define void @dead_on_return_sized(ptr dead_on_return(4) %p) {
; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
; CHECK: attributes [[OPTDEBUG]] = { optdebug }
; CHECK: attributes [[NODIVERGENCESOURCE]] = { nodivergencesource }
+; CHECK: attributes [[NOIPA]] = { noipa }
; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index 8ed76999dc13d..c7cd8bd43ecd7 100644
--- a/llvm/unittests/IR/FunctionTest.cpp
+++ b/llvm/unittests/IR/FunctionTest.cpp
@@ -644,4 +644,15 @@ TEST(FunctionTest, LLVMGetOrInsertFunction) {
EXPECT_EQ(FuncRef, FuncRef2);
}
+TEST(FunctionTest, NoIPAInexact) {
+ LLVMContext Ctx;
+ std::unique_ptr<Module> M = parseIR(Ctx, R"(
+ define void @foo() { bb1: ret void }
+ define void @bar() #0 { bb1: ret void }
+ attributes #0 = { noipa }
+ )");
+ EXPECT_TRUE(M->getFunction("foo")->isDefinitionExact());
+ EXPECT_FALSE(M->getFunction("bar")->isDefinitionExact());
+}
+
} // end namespace
diff --git a/llvm/utils/emacs/llvm-mode.el b/llvm/utils/emacs/llvm-mode.el
index 7dc1c28489839..6ee5a30e5e54c 100644
--- a/llvm/utils/emacs/llvm-mode.el
+++ b/llvm/utils/emacs/llvm-mode.el
@@ -35,7 +35,7 @@
`(,(regexp-opt
'("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "immarg" "inaccessiblememonly"
"inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull" "nocapture"
- "nocallback" "nocf_check" "noduplicate" "noext" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"
+ "nocallback" "nocf_check" "noduplicate" "noext" "nofree" "noimplicitfloat" "noinline" "noipa" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"
"norecurse" "nosync" "noundef" "nounwind" "nosanitize_bounds" "nosanitize_coverage" "null_pointer_is_valid" "optdebug" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
"shadowcallstack" "signext" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_alloc_token" "sanitize_hwaddress" "sanitize_memtag"
"sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "zeroext") 'symbols) . font-lock-constant-face)
diff --git a/llvm/utils/kate/llvm.xml b/llvm/utils/kate/llvm.xml
index c66547d9121ce..0291ed32b3f6c 100644
--- a/llvm/utils/kate/llvm.xml
+++ b/llvm/utils/kate/llvm.xml
@@ -104,6 +104,7 @@
<item> nofree </item>
<item> noimplicitfloat </item>
<item> noinline </item>
+ <item> noipa </item>
<item> nomerge </item>
<item> nooutline </item>
<item> noprofile </item>
diff --git a/llvm/utils/vim/syntax/llvm.vim b/llvm/utils/vim/syntax/llvm.vim
index d921e8bd1e401..bb805dff10a7b 100644
--- a/llvm/utils/vim/syntax/llvm.vim
+++ b/llvm/utils/vim/syntax/llvm.vim
@@ -132,6 +132,7 @@ syn keyword llvmKeyword
\ nofree
\ noimplicitfloat
\ noinline
+ \ noipa
\ nomerge
\ nooutline
\ nonlazybind
diff --git a/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml b/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
index 06d2e43bb3c2e..6a6caccb350a5 100644
--- a/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
+++ b/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
@@ -229,6 +229,7 @@ patterns:
\\bnofree\\b|\
\\bnoimplicitfloat\\b|\
\\bnoinline\\b|\
+ \\bnoipa\\b|\
\\bnomerge\\b|\
\\bnooutline\\b|\
\\bnonlazybind\\b|\
>From 5da5ac739caabbf554b633c737c7f86c8c718973 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Thu, 11 Jun 2026 16:30:15 +0100
Subject: [PATCH 02/23] Tweak formatting
---
llvm/include/llvm/IR/GlobalValue.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 59424f201be84..6e46eced45873 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -493,9 +493,7 @@ class GlobalValue : public Constant {
/// interposable (see \c isInterposable), since in such cases the currently
/// visible variant is *a* correct implementation of the original source
/// function; it just isn't the *only* correct implementation.
- bool isDefinitionExact() const {
- return !mayBeDerefinedOrNoIPA();
- }
+ bool isDefinitionExact() const { return !mayBeDerefinedOrNoIPA(); }
/// Return true if this global has an exact defintion.
bool hasExactDefinition() const {
>From 78a881c945f3d225df2a27db2cd9d45ab6526850 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Thu, 11 Jun 2026 16:56:48 +0100
Subject: [PATCH 03/23] Clarify interaction with inlining
---
llvm/docs/LangRef.rst | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d2a1a32e2c6df..8d6f436161a3b 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2392,9 +2392,12 @@ For example:
with the ``alwaysinline`` attribute.
``noipa``
Disables any interprocedural analysis that inspects the definition of this
- function. Equivalent to moving this function definition to a separate,
- optimizer-opaque, module. Any attributes on the function are still respected
- (as they would be if they remained on a function declaration in this module).
+ function. This attribute is equivalent to moving this function definition to
+ a separate, optimizer-opaque, module. Any attributes on the function are
+ still respected (as they would be if they remained on a function declaration
+ in this module). This attribute does *not* control inlining, which is
+ treated as a separate dimension. Add the ``noinline`` attribute as well in
+ cases where inlining should additionally be disabled.
``nomerge``
This attribute indicates that calls to this function should never be merged
during optimization. For example, it will prevent tail merging otherwise
>From 2232fa16e236f28e7dae4c4cc03bc42c4cd0be8a Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 13:37:03 +0100
Subject: [PATCH 04/23] Add test showing `noipa` controls distinct dimension
from inlining
---
llvm/test/Transforms/Inline/noipa.ll | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 llvm/test/Transforms/Inline/noipa.ll
diff --git a/llvm/test/Transforms/Inline/noipa.ll b/llvm/test/Transforms/Inline/noipa.ll
new file mode 100644
index 0000000000000..31eca22f71d72
--- /dev/null
+++ b/llvm/test/Transforms/Inline/noipa.ll
@@ -0,0 +1,23 @@
+; RUN: opt -passes=inline -S < %s | FileCheck %s
+
+; Ensure `noipa` does _not_ control inlining. The `noipa` attribute controls
+; _other_ interprocedural optimisations by affecting the result of
+; `isDefinitionExact` and `hasExactDefinition` checks, but inlining is
+; controlled separately by the `noinline` attribute.
+
+define internal i32 @noipa(i32 %x) noipa {
+ ret i32 %x
+}
+
+define internal i32 @noipa_noinline(i32 %x) noipa noinline {
+ ret i32 %x
+}
+
+define i32 @bob() {
+ %a = call i32 @noipa(i32 1)
+ %b = call i32 @noipa_noinline(i32 %a)
+ ret i32 %b
+}
+
+; CHECK-NOT: call i32 @noipa(
+; CHECK: call i32 @noipa_noinline(
>From 64d2eaf3e56d89275506a26a60f5c9986813cc0f Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 14:13:51 +0100
Subject: [PATCH 05/23] Adjust ArgumentPromotion pass
---
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 4 ++++
.../test/Transforms/ArgumentPromotion/noipa.ll | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 llvm/test/Transforms/ArgumentPromotion/noipa.ll
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 3be54a710b0ec..dc83d21e643e9 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -817,6 +817,10 @@ static Function *promoteArguments(Function *F, FunctionAnalysisManager &FAM,
if (!F->hasLocalLinkage())
return nullptr;
+ // Ensure function definition is available for interprocedural analysis.
+ if (!F->isDefinitionExact())
+ return nullptr;
+
// Don't promote arguments for variadic functions. Adding, removing, or
// changing non-pack parameters can change the classification of pack
// parameters. Frontends encode that classification at the call site in the
diff --git a/llvm/test/Transforms/ArgumentPromotion/noipa.ll b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
new file mode 100644
index 0000000000000..14bddd80379b3
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
@@ -0,0 +1,18 @@
+; Test: ArgumentPromotion promoting a by-ref argument of a noipa function.
+; If noipa is working, argpromotion should NOT promote the pointer argument,
+; because it requires inspecting the function body to determine load patterns.
+;
+; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
+
+; CHECK: define internal i32 @foo(ptr %p)
+define internal i32 @foo(ptr %p) noipa noinline {
+ %v = load i32, ptr %p
+ ret i32 %v
+}
+
+define i32 @bar() {
+ %a = alloca i32
+ store i32 7, ptr %a
+ %r = call i32 @foo(ptr %a)
+ ret i32 %r
+}
>From 8af0d85364f324cd6c2391435fb8eb4d80bf3176 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 14:25:56 +0100
Subject: [PATCH 06/23] Adjust DeadArgumentElimination pass
---
.../Transforms/IPO/DeadArgumentElimination.cpp | 6 ++++++
llvm/test/Transforms/DeadArgElim/noipa.ll | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 llvm/test/Transforms/DeadArgElim/noipa.ll
diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 65800835ad498..4ec6804be4ed2 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -500,6 +500,12 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) {
return;
}
+ // Ensure function definition is available for interprocedural analysis.
+ if (!F.isDefinitionExact()) {
+ markFrozen(F);
+ return;
+ }
+
unsigned RetCount = numRetVals(&F);
// Assume all return values are dead
diff --git a/llvm/test/Transforms/DeadArgElim/noipa.ll b/llvm/test/Transforms/DeadArgElim/noipa.ll
new file mode 100644
index 0000000000000..064f7ee8e1918
--- /dev/null
+++ b/llvm/test/Transforms/DeadArgElim/noipa.ll
@@ -0,0 +1,16 @@
+; Test: DeadArgumentElimination removing unused args of a noipa function.
+; If noipa is working, DAE should NOT remove the unused argument %y from @foo,
+; because determining which arguments are dead requires inspecting the
+; definition.
+;
+; RUN: opt -passes=deadargelim -S < %s | FileCheck %s
+
+; CHECK: define internal i32 @foo(i32 %x, i32 %y)
+define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
+ ret i32 %x
+}
+
+define i32 @bar() {
+ %r = call i32 @foo(i32 1, i32 2)
+ ret i32 %r
+}
>From 64143bc1996f2504740beeb0af3988c8ac5daea7 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 14:34:53 +0100
Subject: [PATCH 07/23] Adjust GlobalOpt pass
---
llvm/lib/Transforms/IPO/GlobalOpt.cpp | 4 ++++
llvm/test/Transforms/GlobalOpt/noipa.ll | 15 +++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 llvm/test/Transforms/GlobalOpt/noipa.ll
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 75d0f27169822..0618073387d97 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1983,6 +1983,10 @@ OptimizeFunctions(Module &M,
if (!F.hasLocalLinkage())
continue;
+ // Ensure function definition is available for interprocedural analysis.
+ if (!F.isDefinitionExact())
+ continue;
+
// If we have an inalloca parameter that we can safely remove the
// inalloca attribute from, do so. This unlocks optimizations that
// wouldn't be safe in the presence of inalloca.
diff --git a/llvm/test/Transforms/GlobalOpt/noipa.ll b/llvm/test/Transforms/GlobalOpt/noipa.ll
new file mode 100644
index 0000000000000..381e13ea3111c
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/noipa.ll
@@ -0,0 +1,15 @@
+; Test: GlobalOpt changing calling convention of a noipa function.
+; If noipa is working, GlobalOpt should NOT change the CC of @foo,
+; because it requires analyzing callers/callees interprocedurally.
+;
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
+; CHECK: define internal i32 @foo(
+define internal i32 @foo(i32 %x) noipa noinline {
+ ret i32 %x
+}
+
+define i32 @bar() {
+ %r = call i32 @foo(i32 5)
+ ret i32 %r
+}
>From ab4e39a3e4fd1f558d8eb7ab6c01dd1a5dc0fc94 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 14:43:21 +0100
Subject: [PATCH 08/23] Adjust IPSCCP pass
---
llvm/lib/Analysis/ValueLatticeUtils.cpp | 3 ++-
llvm/test/Transforms/SCCP/noipa.ll | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/SCCP/noipa.ll
diff --git a/llvm/lib/Analysis/ValueLatticeUtils.cpp b/llvm/lib/Analysis/ValueLatticeUtils.cpp
index 2bcb4d5b0e6b1..acc19667d7764 100644
--- a/llvm/lib/Analysis/ValueLatticeUtils.cpp
+++ b/llvm/lib/Analysis/ValueLatticeUtils.cpp
@@ -17,7 +17,8 @@
using namespace llvm;
bool llvm::canTrackArgumentsInterprocedurally(Function *F) {
- return F->hasLocalLinkage() && !F->hasAddressTaken();
+ return F->hasExactDefinition() && F->hasLocalLinkage() &&
+ !F->hasAddressTaken();
}
bool llvm::canTrackReturnsInterprocedurally(Function *F) {
diff --git a/llvm/test/Transforms/SCCP/noipa.ll b/llvm/test/Transforms/SCCP/noipa.ll
new file mode 100644
index 0000000000000..0d3cd9cf09c6a
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/noipa.ll
@@ -0,0 +1,16 @@
+; Test: IPSCCP constant-propagating through arguments of a noipa function.
+; If noipa is working, IPSCCP should NOT propagate the constant 42 into @foo,
+; because analyzing calls to @foo to determine argument values is IPA.
+;
+; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
+
+; CHECK: define internal i32 @foo(i32 %x)
+; CHECK-NEXT: ret i32 %x
+define internal i32 @foo(i32 %x) noipa noinline {
+ ret i32 %x
+}
+
+define i32 @bar() {
+ %r = call i32 @foo(i32 42)
+ ret i32 %r
+}
>From f64eb3040a803708cc1fbc52a9ca1f659442e484 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 15:18:32 +0100
Subject: [PATCH 09/23] Adjust MergeFunctions pass
---
llvm/lib/Transforms/IPO/MergeFunctions.cpp | 4 +++-
llvm/test/Transforms/MergeFunc/noipa.ll | 28 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/MergeFunc/noipa.ll
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index ac8a21ea24320..5c8624ba56a27 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -428,6 +428,7 @@ static bool hasDistinctMetadataIntrinsic(const Function &F) {
/// Check whether \p F is eligible for function merging.
static bool isEligibleForMerging(Function &F) {
return !F.isDeclaration() && !F.hasAvailableExternallyLinkage() &&
+ !F.hasFnAttribute(Attribute::NoIPA) &&
!hasDistinctMetadataIntrinsic(F);
}
@@ -473,7 +474,8 @@ template <typename FuncContainer> bool MergeFunctions::run(FuncContainer &M) {
if (!I)
continue;
Function *F = cast<Function>(I);
- if (!F->isDeclaration() && !F->hasAvailableExternallyLinkage()) {
+ if (!F->isDeclaration() && !F->hasAvailableExternallyLinkage() &&
+ !F->hasFnAttribute(Attribute::NoIPA)) {
Changed |= insert(F);
}
}
diff --git a/llvm/test/Transforms/MergeFunc/noipa.ll b/llvm/test/Transforms/MergeFunc/noipa.ll
new file mode 100644
index 0000000000000..329532596c67b
--- /dev/null
+++ b/llvm/test/Transforms/MergeFunc/noipa.ll
@@ -0,0 +1,28 @@
+; Test: MergeFunctions merging a noipa function with an identical one.
+; If noipa is working, MergeFunctions should NOT merge @foo into @baz
+; (or vice versa), because it inspects the function definitions.
+;
+; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
+
+; CHECK: define internal i32 @foo(
+define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
+ %sum = add i32 %x, %y
+ %mul = mul i32 %sum, %x
+ %sub = sub i32 %mul, %y
+ ret i32 %sub
+}
+
+; CHECK: define internal i32 @baz(
+define internal i32 @baz(i32 %x, i32 %y) noipa noinline {
+ %sum = add i32 %x, %y
+ %mul = mul i32 %sum, %x
+ %sub = sub i32 %mul, %y
+ ret i32 %sub
+}
+
+define i32 @bar() {
+ %r1 = call i32 @foo(i32 1, i32 2)
+ %r2 = call i32 @baz(i32 3, i32 4)
+ %r = add i32 %r1, %r2
+ ret i32 %r
+}
>From fade1767819331116fdba7bef402ed10eb450bfd Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Fri, 12 Jun 2026 15:56:06 +0100
Subject: [PATCH 10/23] Add to release notes
---
llvm/docs/ReleaseNotes.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index bdfbfc3f70533..d64aeb85c5448 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -94,6 +94,11 @@ Makes programs 10x faster by doing Special New Thing.
* Fast math flags are now permitted on `uitofp` and `sitofp`.
+* Added `noipa` attribute which disables interprocedural analyses that inspect
+ the definition of the function. This attribute does *not* control inlining,
+ which is treated as a separate dimension. Add the `noinline` attribute as
+ well in cases where inlining should additionally be disabled.
+
### Changes to LLVM infrastructure
* Removed ``Constant::isZeroValue``. It was functionally identical to
>From ca1d88b744c6504a241cb6a1be27822092cf7b89 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Sat, 13 Jun 2026 16:20:07 +0100
Subject: [PATCH 11/23] Adjust FunctionSpecialization pass
---
.../lib/Transforms/IPO/FunctionSpecialization.cpp | 3 +++
.../Transforms/FunctionSpecialization/noipa.ll | 15 +++++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 llvm/test/Transforms/FunctionSpecialization/noipa.ll
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index fb741f35cbd6d..bfec273116566 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -1039,6 +1039,9 @@ bool FunctionSpecializer::isCandidateFunction(Function *F) {
if (F->hasFnAttribute(Attribute::NoDuplicate))
return false;
+ if (F->hasFnAttribute(Attribute::NoIPA))
+ return false;
+
if (F->hasOptSize())
return false;
diff --git a/llvm/test/Transforms/FunctionSpecialization/noipa.ll b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
new file mode 100644
index 0000000000000..890fc5d77aa70
--- /dev/null
+++ b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
@@ -0,0 +1,15 @@
+; Function specialisation should not activate for `noipa` functions.
+;
+; RUN: opt -passes='ipsccp<func-spec>' -force-specialization -S < %s | FileCheck %s
+
+define i32 @foo(i32 %x, i32 %y) noipa {
+ %r2 = add i32 %x, %y
+ ret i32 %r2
+}
+
+; CHECK: call i32 @foo(
+; CHECK-NOT: define internal i32 @foo.specialized.1(
+define i32 @test() {
+ %r = call i32 @foo(i32 0, i32 5)
+ ret i32 %r
+}
>From 3eb2d1d20307571a1c14bcb22c12b16c6494599d Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 16 Jun 2026 16:53:04 +0100
Subject: [PATCH 12/23] Adjust WholeProgramDevirt pass
---
.../lib/Transforms/IPO/WholeProgramDevirt.cpp | 2 +-
.../WholeProgramDevirt/vcp-noipa.ll | 33 +++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 3a03043e32c49..de7fb934536a8 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1924,7 +1924,7 @@ bool DevirtModule::tryVirtualConstProp(
if (!Fn)
return false;
- if (Fn->isDeclaration() ||
+ if (!Fn->hasExactDefinition() ||
!computeFunctionBodyMemoryAccess(*Fn, FAM.getResult<AAManager>(*Fn))
.doesNotAccessMemory() ||
Fn->arg_empty() || !Fn->arg_begin()->use_empty() ||
diff --git a/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll b/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
new file mode 100644
index 0000000000000..0e16934e9e5bc
--- /dev/null
+++ b/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
@@ -0,0 +1,33 @@
+; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s
+
+; The `noipa` attribute prevents interprocedural function body inspection,
+; including this virtual constant propagation transformation.
+
+target datalayout = "e-p:64:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at vt1 = constant [1 x ptr] [ptr @vf1], !type !0
+ at vt2 = constant [1 x ptr] [ptr @vf2], !type !0
+
+define i32 @vf1(ptr %this, i32 %arg) readnone noipa {
+ ret i32 %arg
+}
+
+define i32 @vf2(ptr %this, i32 %arg) readnone {
+ ret i32 %arg
+}
+
+; CHECK: define i32 @fn
+define i32 @fn(ptr %obj) {
+ %vtable = load ptr, ptr %obj
+ %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid")
+ call void @llvm.assume(i1 %p)
+ %fptr = load ptr, ptr %vtable
+ ; CHECK: call i32 %
+ %result = call i32 %fptr(ptr %obj, i32 1)
+ ret i32 %result
+}
+declare i1 @llvm.type.test(ptr, metadata)
+declare void @llvm.assume(i1)
+
+!0 = !{i32 0, !"typeid"}
>From b8c24f65086283338b785a6a8cffaabe95a2cc64 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 16 Jun 2026 17:23:47 +0100
Subject: [PATCH 13/23] Revise WholeProgramDevirt check
---
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index de7fb934536a8..999bf937cff4d 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1924,7 +1924,7 @@ bool DevirtModule::tryVirtualConstProp(
if (!Fn)
return false;
- if (!Fn->hasExactDefinition() ||
+ if (Fn->isDeclaration() || Fn->hasFnAttribute(Attribute::NoIPA) ||
!computeFunctionBodyMemoryAccess(*Fn, FAM.getResult<AAManager>(*Fn))
.doesNotAccessMemory() ||
Fn->arg_empty() || !Fn->arg_begin()->use_empty() ||
>From db8652a1116609b14db303dc4a4a738eb2c948ff Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 16 Jun 2026 17:31:27 +0100
Subject: [PATCH 14/23] Mention outlining in feature descriptions
---
llvm/docs/LangRef.rst | 6 +++---
llvm/docs/ReleaseNotes.md | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index ce2269a62fb69..75f7e57729a5d 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2395,9 +2395,9 @@ For example:
function. This attribute is equivalent to moving this function definition to
a separate, optimizer-opaque, module. Any attributes on the function are
still respected (as they would be if they remained on a function declaration
- in this module). This attribute does *not* control inlining, which is
- treated as a separate dimension. Add the ``noinline`` attribute as well in
- cases where inlining should additionally be disabled.
+ in this module). This attribute does *not* control inlining or outlining.
+ Add the ``noinline`` and ``nooutline`` attributes as well in cases where
+ inlining and outlining should additionally be disabled.
``nomerge``
This attribute indicates that calls to this function should never be merged
during optimization. For example, it will prevent tail merging otherwise
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index a2a307bfd130b..bf21de9b43e94 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -98,9 +98,9 @@ Makes programs 10x faster by doing Special New Thing.
ISO 18037 fixed-point ``printf`` specifiers.
* Added `noipa` attribute which disables interprocedural analyses that inspect
- the definition of the function. This attribute does *not* control inlining,
- which is treated as a separate dimension. Add the `noinline` attribute as
- well in cases where inlining should additionally be disabled.
+ the definition of the function. This attribute does *not* control inlining or
+ outlining. Add the `noinline` and `nooutline` attributes as well in cases
+ where inlining and outlining should additionally be disabled.
### Changes to LLVM infrastructure
>From 3201924d22a38af660fb9664ab20894eca07dc99 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Wed, 17 Jun 2026 15:33:28 +0100
Subject: [PATCH 15/23] Address review feedback
---
llvm/include/llvm/Bitcode/LLVMBitCodes.h | 2 +-
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +-
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
llvm/lib/IR/Globals.cpp | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 5c2b681cc3d63..af4cac996a78c 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -820,7 +820,7 @@ enum AttributeKindCodes {
ATTR_KIND_DENORMAL_FPENV = 106,
ATTR_KIND_NOOUTLINE = 107,
ATTR_KIND_FLATTEN = 108,
- ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS = 109,
+ ATTR_KIND_NOIPA = 109,
};
enum ComdatSelectionKindCodes {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index f8512a3440630..6cd95c9c533b3 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2302,7 +2302,7 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::DenormalFPEnv;
case bitc::ATTR_KIND_NOOUTLINE:
return Attribute::NoOutline;
- case bitc::ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS:
+ case bitc::ATTR_KIND_NOIPA:
return Attribute::NoIPA;
}
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index f8f5c6953f94a..c4058fe66ff0b 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1009,7 +1009,7 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
case Attribute::NoOutline:
return bitc::ATTR_KIND_NOOUTLINE;
case Attribute::NoIPA:
- return bitc::ATTR_KIND_NO_INTERPROCEDURAL_ANALYSIS;
+ return bitc::ATTR_KIND_NOIPA;
case Attribute::EndAttrKinds:
llvm_unreachable("Can not encode end-attribute kinds marker.");
case Attribute::None:
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 422517dd05843..f566a358dbfb9 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -336,7 +336,7 @@ bool GlobalValue::isNobuiltinFnDef() const {
bool GlobalValue::isNoipaFnDef() const {
const Function *F = dyn_cast<Function>(this);
- if (!F || F->empty())
+ if (!F || F->isDeclaration())
return false;
return F->hasFnAttribute(Attribute::NoIPA);
}
>From c827d17bb684a294806f05820b41cd79afa130bc Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Wed, 17 Jun 2026 15:41:09 +0100
Subject: [PATCH 16/23] Tweak test style
---
llvm/test/Transforms/ArgumentPromotion/noipa.ll | 4 ++--
llvm/test/Transforms/DeadArgElim/noipa.ll | 4 ++--
llvm/test/Transforms/FunctionSpecialization/noipa.ll | 4 ++--
llvm/test/Transforms/GlobalOpt/noipa.ll | 4 ++--
llvm/test/Transforms/MergeFunc/noipa.ll | 4 ++--
llvm/test/Transforms/SCCP/noipa.ll | 4 ++--
llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll | 3 ---
7 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/llvm/test/Transforms/ArgumentPromotion/noipa.ll b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
index 14bddd80379b3..8cb3ccf295c7b 100644
--- a/llvm/test/Transforms/ArgumentPromotion/noipa.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
@@ -1,8 +1,8 @@
+; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
+
; Test: ArgumentPromotion promoting a by-ref argument of a noipa function.
; If noipa is working, argpromotion should NOT promote the pointer argument,
; because it requires inspecting the function body to determine load patterns.
-;
-; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
; CHECK: define internal i32 @foo(ptr %p)
define internal i32 @foo(ptr %p) noipa noinline {
diff --git a/llvm/test/Transforms/DeadArgElim/noipa.ll b/llvm/test/Transforms/DeadArgElim/noipa.ll
index 064f7ee8e1918..bb8c6ab9a3b0b 100644
--- a/llvm/test/Transforms/DeadArgElim/noipa.ll
+++ b/llvm/test/Transforms/DeadArgElim/noipa.ll
@@ -1,9 +1,9 @@
+; RUN: opt -passes=deadargelim -S < %s | FileCheck %s
+
; Test: DeadArgumentElimination removing unused args of a noipa function.
; If noipa is working, DAE should NOT remove the unused argument %y from @foo,
; because determining which arguments are dead requires inspecting the
; definition.
-;
-; RUN: opt -passes=deadargelim -S < %s | FileCheck %s
; CHECK: define internal i32 @foo(i32 %x, i32 %y)
define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
diff --git a/llvm/test/Transforms/FunctionSpecialization/noipa.ll b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
index 890fc5d77aa70..f65f383e61cdc 100644
--- a/llvm/test/Transforms/FunctionSpecialization/noipa.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
@@ -1,7 +1,7 @@
-; Function specialisation should not activate for `noipa` functions.
-;
; RUN: opt -passes='ipsccp<func-spec>' -force-specialization -S < %s | FileCheck %s
+; Function specialisation should not activate for `noipa` functions.
+
define i32 @foo(i32 %x, i32 %y) noipa {
%r2 = add i32 %x, %y
ret i32 %r2
diff --git a/llvm/test/Transforms/GlobalOpt/noipa.ll b/llvm/test/Transforms/GlobalOpt/noipa.ll
index 381e13ea3111c..71d0e579b4e6e 100644
--- a/llvm/test/Transforms/GlobalOpt/noipa.ll
+++ b/llvm/test/Transforms/GlobalOpt/noipa.ll
@@ -1,8 +1,8 @@
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
; Test: GlobalOpt changing calling convention of a noipa function.
; If noipa is working, GlobalOpt should NOT change the CC of @foo,
; because it requires analyzing callers/callees interprocedurally.
-;
-; RUN: opt -passes=globalopt -S < %s | FileCheck %s
; CHECK: define internal i32 @foo(
define internal i32 @foo(i32 %x) noipa noinline {
diff --git a/llvm/test/Transforms/MergeFunc/noipa.ll b/llvm/test/Transforms/MergeFunc/noipa.ll
index 329532596c67b..d515ea3822580 100644
--- a/llvm/test/Transforms/MergeFunc/noipa.ll
+++ b/llvm/test/Transforms/MergeFunc/noipa.ll
@@ -1,8 +1,8 @@
+; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
+
; Test: MergeFunctions merging a noipa function with an identical one.
; If noipa is working, MergeFunctions should NOT merge @foo into @baz
; (or vice versa), because it inspects the function definitions.
-;
-; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
; CHECK: define internal i32 @foo(
define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
diff --git a/llvm/test/Transforms/SCCP/noipa.ll b/llvm/test/Transforms/SCCP/noipa.ll
index 0d3cd9cf09c6a..cd475ed188c75 100644
--- a/llvm/test/Transforms/SCCP/noipa.ll
+++ b/llvm/test/Transforms/SCCP/noipa.ll
@@ -1,8 +1,8 @@
+; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
+
; Test: IPSCCP constant-propagating through arguments of a noipa function.
; If noipa is working, IPSCCP should NOT propagate the constant 42 into @foo,
; because analyzing calls to @foo to determine argument values is IPA.
-;
-; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
; CHECK: define internal i32 @foo(i32 %x)
; CHECK-NEXT: ret i32 %x
diff --git a/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll b/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
index 0e16934e9e5bc..7d1bdd2489028 100644
--- a/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
+++ b/llvm/test/Transforms/WholeProgramDevirt/vcp-noipa.ll
@@ -3,9 +3,6 @@
; The `noipa` attribute prevents interprocedural function body inspection,
; including this virtual constant propagation transformation.
-target datalayout = "e-p:64:64"
-target triple = "x86_64-unknown-linux-gnu"
-
@vt1 = constant [1 x ptr] [ptr @vf1], !type !0
@vt2 = constant [1 x ptr] [ptr @vf2], !type !0
>From ebdebcb8b2cbd26d014336e7da82158b530f444d Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Wed, 17 Jun 2026 16:50:00 +0100
Subject: [PATCH 17/23] Adjust GlobalOpt ifunc resolver checks
---
llvm/lib/Transforms/IPO/GlobalOpt.cpp | 6 ++
.../GlobalOpt/resolve-fmv-ifunc-noipa.ll | 76 +++++++++++++++++++
.../GlobalOpt/resolve-static-ifunc-noipa.ll | 21 +++++
3 files changed, 103 insertions(+)
create mode 100644 llvm/test/Transforms/GlobalOpt/resolve-fmv-ifunc-noipa.ll
create mode 100644 llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 0618073387d97..dc43c2bc61379 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2455,6 +2455,9 @@ static Function *hasSideeffectFreeStaticResolution(GlobalIFunc &IF) {
if (Resolver->isInterposable())
return nullptr;
+ if (Resolver->hasFnAttribute(Attribute::NoIPA))
+ return nullptr;
+
// Only handle functions that have been optimized into a single basic block.
auto It = Resolver->begin();
if (++It != Resolver->end())
@@ -2575,6 +2578,9 @@ static bool OptimizeNonTrivialIFuncs(
if (Resolver->isInterposable())
continue;
+ if (Resolver->hasFnAttribute(Attribute::NoIPA))
+ continue;
+
SmallVector<Function *> Versions;
// Discover the versioned functions.
if (any_of(*Resolver, [&](BasicBlock &BB) {
diff --git a/llvm/test/Transforms/GlobalOpt/resolve-fmv-ifunc-noipa.ll b/llvm/test/Transforms/GlobalOpt/resolve-fmv-ifunc-noipa.ll
new file mode 100644
index 0000000000000..6b373eef7977e
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/resolve-fmv-ifunc-noipa.ll
@@ -0,0 +1,76 @@
+; REQUIRES: aarch64-registered-target
+
+; RUN: opt --passes=globalopt -o - -S < %s | FileCheck %s
+
+; `noipa` resolvers are not eligible for inspection
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+$callee.resolver = comdat any
+$caller.resolver = comdat any
+
+ at __aarch64_cpu_features = external local_unnamed_addr global { i64 }
+
+ at callee = weak_odr ifunc i32 (), ptr @callee.resolver
+ at caller = weak_odr ifunc i32 (), ptr @caller.resolver
+
+declare void @__init_cpu_features_resolver() local_unnamed_addr
+
+declare i32 @callee.default() #0
+declare i32 @callee._Msve() #1
+declare i32 @callee._Msve2() #2
+
+define weak_odr ptr @callee.resolver() noipa comdat {
+resolver_entry:
+ tail call void @__init_cpu_features_resolver()
+ %0 = load i64, ptr @__aarch64_cpu_features, align 8
+ %1 = and i64 %0, 69793284352
+ %2 = icmp eq i64 %1, 69793284352
+ %3 = and i64 %0, 1073807616
+ %4 = icmp eq i64 %3, 1073807616
+ %callee._Msve.callee.default = select i1 %4, ptr @callee._Msve, ptr @callee.default
+ %common.ret.op = select i1 %2, ptr @callee._Msve2, ptr %callee._Msve.callee.default
+ ret ptr %common.ret.op
+}
+
+; CHECK: define i32 @caller._Msve()
+; CHECK: tail call i32 @callee()
+define i32 @caller._Msve() #1 {
+entry:
+ %call = tail call i32 @callee()
+ ret i32 %call
+}
+
+; CHECK: define i32 @caller._Msve2()
+; CHECK: tail call i32 @callee()
+define i32 @caller._Msve2() #2 {
+entry:
+ %call = tail call i32 @callee()
+ ret i32 %call
+}
+
+; CHECK: define i32 @caller.default()
+; CHECK: tail call i32 @callee()
+define i32 @caller.default() #0 {
+entry:
+ %call = tail call i32 @callee()
+ ret i32 %call
+}
+
+define weak_odr ptr @caller.resolver() comdat {
+resolver_entry:
+ tail call void @__init_cpu_features_resolver()
+ %0 = load i64, ptr @__aarch64_cpu_features, align 8
+ %1 = and i64 %0, 69793284352
+ %2 = icmp eq i64 %1, 69793284352
+ %3 = and i64 %0, 1073807616
+ %4 = icmp eq i64 %3, 1073807616
+ %caller._Msve.caller.default = select i1 %4, ptr @caller._Msve, ptr @caller.default
+ %common.ret.op = select i1 %2, ptr @caller._Msve2, ptr %caller._Msve.caller.default
+ ret ptr %common.ret.op
+}
+
+attributes #0 = { "fmv-features" }
+attributes #1 = { "fmv-features"="sve" }
+attributes #2 = { "fmv-features"="sve2" }
diff --git a/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll b/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
new file mode 100644
index 0000000000000..f2aa709afa111
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
@@ -0,0 +1,21 @@
+; RUN: opt --passes=globalopt -o - -S < %s | FileCheck %s
+
+; `noipa` resolvers are not eligible for inspection
+
+ at static.ifunc = internal ifunc void (), ptr @static.resolver
+
+define ptr @static.resolver() noipa {
+ ret ptr @static._Msimd
+}
+define void @static._Msimd() {
+ ret void
+}
+define void @static.default() {
+ ret void
+}
+
+define void @caller() {
+ ; CHECK: call void @static.ifunc()
+ call void @static.ifunc()
+ ret void
+}
>From 1d1e1d7a6dbec378457a5545c4b6bafed42aa92a Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Mon, 22 Jun 2026 16:28:27 +0100
Subject: [PATCH 18/23] Adjust Evaluator pass utility
---
llvm/lib/Transforms/Utils/Evaluator.cpp | 3 ++-
.../GlobalOpt/global-constructor-noipa.ll | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index 2b3dfdc4f01f5..9d89398da3e5d 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -483,7 +483,8 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
// Resolve function pointers.
SmallVector<Constant *, 8> Formals;
Function *Callee = getCalleeWithFormalArgs(CB, Formals);
- if (!Callee || Callee->isInterposable()) {
+ if (!Callee || Callee->isInterposable() ||
+ Callee->hasFnAttribute(Attribute::NoIPA)) {
LLVM_DEBUG(dbgs() << "Can not resolve function pointer.\n");
return false; // Cannot resolve.
}
diff --git a/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll b/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
new file mode 100644
index 0000000000000..f37c648f4171c
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
@@ -0,0 +1,18 @@
+; RUN: opt -passes=globalopt -S -o - < %s | FileCheck %s
+
+; Calls to `noipa` functions in constructors prevent evaluation.
+
+; CHECK: @object = local_unnamed_addr global i32 0
+ at object = local_unnamed_addr global i32 0
+define void @ctor() {
+ store i32 4, ptr @object
+ %a = bitcast ptr @object to ptr
+ call void @test(ptr %a)
+ ret void
+}
+
+define void @test(ptr %ptr) noipa {
+ ret void
+}
+
+ at llvm.global_ctors = appending constant [1 x { i32, ptr, ptr }] [ { i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null } ]
>From d9c292a4e93b853eb387ca6203d816ea40a849ae Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Mon, 22 Jun 2026 16:58:48 +0100
Subject: [PATCH 19/23] Move `noipa` check to `isInterposable`
---
llvm/include/llvm/IR/GlobalValue.h | 16 +++++++++++-----
llvm/lib/Analysis/InlineCost.cpp | 2 +-
llvm/lib/IR/Globals.cpp | 4 +++-
llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 12 ++++++------
.../Transforms/IPO/FunctionSpecialization.cpp | 3 ---
llvm/lib/Transforms/IPO/GlobalOpt.cpp | 6 ------
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 1 -
llvm/lib/Transforms/Utils/Evaluator.cpp | 3 +--
8 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 6e46eced45873..7a23c1cb00a14 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -136,7 +136,7 @@ class GlobalValue : public Constant {
/// Returns true if the definition of this global may be replaced by a
/// differently optimized variant of the same source level function at link
/// time.
- bool mayBeDerefinedOrNoIPA() const {
+ bool mayBeDerefined() const {
switch (getLinkage()) {
case WeakODRLinkage:
case LinkOnceODRLinkage:
@@ -155,7 +155,7 @@ class GlobalValue : public Constant {
// nobuiltin due to attributes at call-sites. To avoid applying IPO based
// on nobuiltin semantics, treat such function definitions as maybe
// derefined.
- return isInterposable() || isNobuiltinFnDef() || isNoipaFnDef();
+ return isInterposable() || isNobuiltinFnDef();
}
llvm_unreachable("Fully covered switch above!");
@@ -493,7 +493,9 @@ class GlobalValue : public Constant {
/// interposable (see \c isInterposable), since in such cases the currently
/// visible variant is *a* correct implementation of the original source
/// function; it just isn't the *only* correct implementation.
- bool isDefinitionExact() const { return !mayBeDerefinedOrNoIPA(); }
+ bool isDefinitionExact() const {
+ return !mayBeDerefined();
+ }
/// Return true if this global has an exact defintion.
bool hasExactDefinition() const {
@@ -508,8 +510,12 @@ class GlobalValue : public Constant {
/// Return true if this global's definition can be substituted with an
/// *arbitrary* definition at link time or load time. We cannot do any IPO or
/// inlining across interposable call edges, since the callee can be
- /// replaced with something arbitrary.
- LLVM_ABI bool isInterposable() const;
+ /// replaced with something arbitrary. For most IPO passes, the `noipa`
+ /// attribute on a function definition is also treated as if it were
+ /// interposable (and thus blocking interprocedural analysis). Passes
+ /// which already have their own distinct control attributes (e.g. inlining)
+ /// may set `CheckNoIPA = false` when calling this.
+ LLVM_ABI bool isInterposable(bool CheckNoIPA = true) const;
LLVM_ABI bool canBenefitFromLocalAlias() const;
bool hasExternalLinkage() const { return isExternalLinkage(getLinkage()); }
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index d975a93e9b1fd..e0cfa2ff106db 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -3246,7 +3246,7 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
return InlineResult::failure("optnone attribute");
// Don't inline functions which can be interposed at link-time.
- if (Callee->isInterposable())
+ if (Callee->isInterposable(/* CheckNoIPA = */ false))
return InlineResult::failure("interposable");
// Don't inline functions marked noinline.
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index f566a358dbfb9..9685231d3ea32 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -113,7 +113,9 @@ GlobalObject::~GlobalObject() {
setComdat(nullptr);
}
-bool GlobalValue::isInterposable() const {
+bool GlobalValue::isInterposable(bool CheckNoIPA) const {
+ if (CheckNoIPA && isNoipaFnDef())
+ return true;
if (isInterposableLinkage(getLinkage()))
return true;
return !isDSOLocal() && getParent() &&
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 497914403ac68..d98d3a1c46309 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -976,7 +976,7 @@ static void addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes,
for (Function *F : SCCNodes) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
continue;
@@ -1250,7 +1250,7 @@ static void addArgumentAttrs(const SCCNodeSet &SCCNodes,
for (Function *F : SCCNodes) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
continue;
@@ -1503,7 +1503,7 @@ static void addNoAliasAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
return;
@@ -1620,7 +1620,7 @@ static void addNonNullAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
return;
@@ -1674,7 +1674,7 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
return;
@@ -2154,7 +2154,7 @@ static void addColdAttrs(const SCCNodeSet &SCCNodes,
static bool functionWillReturn(const Function &F) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
- // For more details, see GlobalValue::mayBeDerefinedOrNoIPA.
+ // For more details, see GlobalValue::mayBeDerefined.
if (!F.hasExactDefinition())
return false;
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 57a972b3d0d48..a4844006319c9 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -1042,9 +1042,6 @@ bool FunctionSpecializer::isCandidateFunction(Function *F) {
if (F->hasFnAttribute(Attribute::NoDuplicate))
return false;
- if (F->hasFnAttribute(Attribute::NoIPA))
- return false;
-
if (F->hasOptSize())
return false;
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index dc43c2bc61379..0618073387d97 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2455,9 +2455,6 @@ static Function *hasSideeffectFreeStaticResolution(GlobalIFunc &IF) {
if (Resolver->isInterposable())
return nullptr;
- if (Resolver->hasFnAttribute(Attribute::NoIPA))
- return nullptr;
-
// Only handle functions that have been optimized into a single basic block.
auto It = Resolver->begin();
if (++It != Resolver->end())
@@ -2578,9 +2575,6 @@ static bool OptimizeNonTrivialIFuncs(
if (Resolver->isInterposable())
continue;
- if (Resolver->hasFnAttribute(Attribute::NoIPA))
- continue;
-
SmallVector<Function *> Versions;
// Discover the versioned functions.
if (any_of(*Resolver, [&](BasicBlock &BB) {
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index faeca909b85e4..e1da7b7cd4e92 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1925,7 +1925,6 @@ bool DevirtModule::tryVirtualConstProp(
return false;
if (Fn->isDeclaration() || Fn->isInterposable() ||
- Fn->hasFnAttribute(Attribute::NoIPA) ||
!computeFunctionBodyMemoryAccess(*Fn, FAM.getResult<AAManager>(*Fn))
.doesNotAccessMemory() ||
Fn->arg_empty() || !Fn->arg_begin()->use_empty() ||
diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index 9d89398da3e5d..2b3dfdc4f01f5 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -483,8 +483,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
// Resolve function pointers.
SmallVector<Constant *, 8> Formals;
Function *Callee = getCalleeWithFormalArgs(CB, Formals);
- if (!Callee || Callee->isInterposable() ||
- Callee->hasFnAttribute(Attribute::NoIPA)) {
+ if (!Callee || Callee->isInterposable()) {
LLVM_DEBUG(dbgs() << "Can not resolve function pointer.\n");
return false; // Cannot resolve.
}
>From 148f130b84578cdb220e70067e135bdad5da4411 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 23 Jun 2026 13:39:14 +0100
Subject: [PATCH 20/23] Remove 'Test:' prefix from test descriptions
---
llvm/test/Transforms/ArgumentPromotion/noipa.ll | 2 +-
llvm/test/Transforms/DeadArgElim/noipa.ll | 2 +-
llvm/test/Transforms/GlobalOpt/noipa.ll | 2 +-
llvm/test/Transforms/MergeFunc/noipa.ll | 2 +-
llvm/test/Transforms/SCCP/noipa.ll | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/test/Transforms/ArgumentPromotion/noipa.ll b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
index 8cb3ccf295c7b..8b83acd05b0f1 100644
--- a/llvm/test/Transforms/ArgumentPromotion/noipa.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
@@ -1,6 +1,6 @@
; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
-; Test: ArgumentPromotion promoting a by-ref argument of a noipa function.
+; ArgumentPromotion promoting a by-ref argument of a noipa function.
; If noipa is working, argpromotion should NOT promote the pointer argument,
; because it requires inspecting the function body to determine load patterns.
diff --git a/llvm/test/Transforms/DeadArgElim/noipa.ll b/llvm/test/Transforms/DeadArgElim/noipa.ll
index bb8c6ab9a3b0b..aed0a01a2c82f 100644
--- a/llvm/test/Transforms/DeadArgElim/noipa.ll
+++ b/llvm/test/Transforms/DeadArgElim/noipa.ll
@@ -1,6 +1,6 @@
; RUN: opt -passes=deadargelim -S < %s | FileCheck %s
-; Test: DeadArgumentElimination removing unused args of a noipa function.
+; DeadArgumentElimination removing unused args of a noipa function.
; If noipa is working, DAE should NOT remove the unused argument %y from @foo,
; because determining which arguments are dead requires inspecting the
; definition.
diff --git a/llvm/test/Transforms/GlobalOpt/noipa.ll b/llvm/test/Transforms/GlobalOpt/noipa.ll
index 71d0e579b4e6e..64be84501e63e 100644
--- a/llvm/test/Transforms/GlobalOpt/noipa.ll
+++ b/llvm/test/Transforms/GlobalOpt/noipa.ll
@@ -1,6 +1,6 @@
; RUN: opt -passes=globalopt -S < %s | FileCheck %s
-; Test: GlobalOpt changing calling convention of a noipa function.
+; GlobalOpt changing calling convention of a noipa function.
; If noipa is working, GlobalOpt should NOT change the CC of @foo,
; because it requires analyzing callers/callees interprocedurally.
diff --git a/llvm/test/Transforms/MergeFunc/noipa.ll b/llvm/test/Transforms/MergeFunc/noipa.ll
index d515ea3822580..0c993bfef4e2a 100644
--- a/llvm/test/Transforms/MergeFunc/noipa.ll
+++ b/llvm/test/Transforms/MergeFunc/noipa.ll
@@ -1,6 +1,6 @@
; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
-; Test: MergeFunctions merging a noipa function with an identical one.
+; MergeFunctions merging a noipa function with an identical one.
; If noipa is working, MergeFunctions should NOT merge @foo into @baz
; (or vice versa), because it inspects the function definitions.
diff --git a/llvm/test/Transforms/SCCP/noipa.ll b/llvm/test/Transforms/SCCP/noipa.ll
index cd475ed188c75..4cae55214665f 100644
--- a/llvm/test/Transforms/SCCP/noipa.ll
+++ b/llvm/test/Transforms/SCCP/noipa.ll
@@ -1,6 +1,6 @@
; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
-; Test: IPSCCP constant-propagating through arguments of a noipa function.
+; IPSCCP constant-propagating through arguments of a noipa function.
; If noipa is working, IPSCCP should NOT propagate the constant 42 into @foo,
; because analyzing calls to @foo to determine argument values is IPA.
>From f4e8d4c7422caef9eea2c4ddb0558cc709c28215 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 23 Jun 2026 13:41:26 +0100
Subject: [PATCH 21/23] Tweak argument comment style
---
llvm/lib/Analysis/InlineCost.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index e0cfa2ff106db..4bfbb33ac5ae3 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -3246,7 +3246,7 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
return InlineResult::failure("optnone attribute");
// Don't inline functions which can be interposed at link-time.
- if (Callee->isInterposable(/* CheckNoIPA = */ false))
+ if (Callee->isInterposable(/*CheckNoIPA=*/false))
return InlineResult::failure("interposable");
// Don't inline functions marked noinline.
>From 167e41296c57b5b5a67184ea890cb9a2aeb97bf4 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 23 Jun 2026 13:46:03 +0100
Subject: [PATCH 22/23] Add `isInterposable()` to unit test
---
llvm/unittests/IR/FunctionTest.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index c7cd8bd43ecd7..82b67c6e629b4 100644
--- a/llvm/unittests/IR/FunctionTest.cpp
+++ b/llvm/unittests/IR/FunctionTest.cpp
@@ -644,14 +644,16 @@ TEST(FunctionTest, LLVMGetOrInsertFunction) {
EXPECT_EQ(FuncRef, FuncRef2);
}
-TEST(FunctionTest, NoIPAInexact) {
+TEST(FunctionTest, NoIPAInterposable) {
LLVMContext Ctx;
std::unique_ptr<Module> M = parseIR(Ctx, R"(
define void @foo() { bb1: ret void }
define void @bar() #0 { bb1: ret void }
attributes #0 = { noipa }
)");
+ EXPECT_FALSE(M->getFunction("foo")->isInterposable());
EXPECT_TRUE(M->getFunction("foo")->isDefinitionExact());
+ EXPECT_TRUE(M->getFunction("bar")->isInterposable());
EXPECT_FALSE(M->getFunction("bar")->isDefinitionExact());
}
>From eccc07415b63c347a94f51fe97b50082a2055385 Mon Sep 17 00:00:00 2001
From: "J. Ryan Stinnett" <ryan at convolv.es>
Date: Tue, 23 Jun 2026 14:59:43 +0100
Subject: [PATCH 23/23] Extend tests
---
.../Transforms/ArgumentPromotion/noipa.ll | 19 ++++++---
llvm/test/Transforms/DeadArgElim/noipa.ll | 17 +++++---
.../FunctionSpecialization/noipa.ll | 17 ++++++--
.../GlobalOpt/global-constructor-noipa.ll | 24 +++++++++--
llvm/test/Transforms/GlobalOpt/noipa.ll | 17 +++++---
.../GlobalOpt/resolve-static-ifunc-noipa.ll | 12 +++++-
llvm/test/Transforms/Inline/noipa.ll | 2 +-
llvm/test/Transforms/MergeFunc/noipa.ll | 41 +++++++++++++++----
llvm/test/Transforms/SCCP/noipa.ll | 17 ++++++--
9 files changed, 129 insertions(+), 37 deletions(-)
diff --git a/llvm/test/Transforms/ArgumentPromotion/noipa.ll b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
index 8b83acd05b0f1..a70e8d0aa0ecc 100644
--- a/llvm/test/Transforms/ArgumentPromotion/noipa.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/noipa.ll
@@ -1,11 +1,17 @@
; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
-; ArgumentPromotion promoting a by-ref argument of a noipa function.
-; If noipa is working, argpromotion should NOT promote the pointer argument,
+; ArgumentPromotion promoting a by-ref argument of a `noipa` function.
+; If `noipa` is working, argpromotion should NOT promote the pointer argument,
; because it requires inspecting the function body to determine load patterns.
-; CHECK: define internal i32 @foo(ptr %p)
-define internal i32 @foo(ptr %p) noipa noinline {
+; CHECK: define internal i32 @foo(i32 %p.0.val)
+define internal i32 @foo(ptr %p) noinline {
+ %v = load i32, ptr %p
+ ret i32 %v
+}
+
+; CHECK: define internal i32 @foo_noipa(ptr %p)
+define internal i32 @foo_noipa(ptr %p) noipa noinline {
%v = load i32, ptr %p
ret i32 %v
}
@@ -14,5 +20,8 @@ define i32 @bar() {
%a = alloca i32
store i32 7, ptr %a
%r = call i32 @foo(ptr %a)
- ret i32 %r
+ %b = alloca i32
+ store i32 %r, ptr %b
+ %s = call i32 @foo_noipa(ptr %b)
+ ret i32 %s
}
diff --git a/llvm/test/Transforms/DeadArgElim/noipa.ll b/llvm/test/Transforms/DeadArgElim/noipa.ll
index aed0a01a2c82f..2834f5fed4ccb 100644
--- a/llvm/test/Transforms/DeadArgElim/noipa.ll
+++ b/llvm/test/Transforms/DeadArgElim/noipa.ll
@@ -1,16 +1,23 @@
; RUN: opt -passes=deadargelim -S < %s | FileCheck %s
-; DeadArgumentElimination removing unused args of a noipa function.
-; If noipa is working, DAE should NOT remove the unused argument %y from @foo,
+; DeadArgumentElimination removing unused args of a `noipa` function.
+; If `noipa` is working, DAE should NOT remove the unused argument %y from @foo,
; because determining which arguments are dead requires inspecting the
; definition.
-; CHECK: define internal i32 @foo(i32 %x, i32 %y)
-define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
+; CHECK: define internal i32 @foo(i32 %x)
+define internal i32 @foo(i32 %x, i32 %y) noinline {
+ ret i32 %x
+}
+
+; CHECK: define internal i32 @foo_noipa(i32 %x, i32 %y)
+define internal i32 @foo_noipa(i32 %x, i32 %y) noipa noinline {
ret i32 %x
}
define i32 @bar() {
%r = call i32 @foo(i32 1, i32 2)
- ret i32 %r
+ %s = call i32 @foo_noipa(i32 1, i32 2)
+ %res = add i32 %r, %s
+ ret i32 %res
}
diff --git a/llvm/test/Transforms/FunctionSpecialization/noipa.ll b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
index f65f383e61cdc..e97247a16defb 100644
--- a/llvm/test/Transforms/FunctionSpecialization/noipa.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/noipa.ll
@@ -2,14 +2,23 @@
; Function specialisation should not activate for `noipa` functions.
-define i32 @foo(i32 %x, i32 %y) noipa {
+define i32 @foo(i32 %x, i32 %y) {
%r2 = add i32 %x, %y
ret i32 %r2
}
-; CHECK: call i32 @foo(
-; CHECK-NOT: define internal i32 @foo.specialized.1(
+define i32 @foo_noipa(i32 %x, i32 %y) noipa {
+ %r2 = add i32 %x, %y
+ ret i32 %r2
+}
+
+; CHECK: call i32 @foo.specialized.1(
+; CHECK: call i32 @foo_noipa(
+; CHECK: define internal i32 @foo.specialized.1(
+; CHECK-NOT: define internal i32 @foo_noipa.specialized.1(
define i32 @test() {
%r = call i32 @foo(i32 0, i32 5)
- ret i32 %r
+ %s = call i32 @foo_noipa(i32 0, i32 5)
+ %res = add i32 %r, %s
+ ret i32 %res
}
diff --git a/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll b/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
index f37c648f4171c..00caa3595af27 100644
--- a/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
+++ b/llvm/test/Transforms/GlobalOpt/global-constructor-noipa.ll
@@ -2,8 +2,9 @@
; Calls to `noipa` functions in constructors prevent evaluation.
-; CHECK: @object = local_unnamed_addr global i32 0
+; CHECK: @object = local_unnamed_addr global i32 4
@object = local_unnamed_addr global i32 0
+
define void @ctor() {
store i32 4, ptr @object
%a = bitcast ptr @object to ptr
@@ -11,8 +12,25 @@ define void @ctor() {
ret void
}
-define void @test(ptr %ptr) noipa {
+define void @test(ptr %ptr) {
+ ret void
+}
+
+; CHECK: @object_noipa = local_unnamed_addr global i32 0
+ at object_noipa = local_unnamed_addr global i32 0
+
+define void @ctor_noipa() {
+ store i32 4, ptr @object_noipa
+ %a = bitcast ptr @object_noipa to ptr
+ call void @test_noipa(ptr %a)
+ ret void
+}
+
+define void @test_noipa(ptr %ptr) noipa {
ret void
}
- at llvm.global_ctors = appending constant [1 x { i32, ptr, ptr }] [ { i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null } ]
+ at llvm.global_ctors = appending constant
+ [2 x { i32, ptr, ptr }]
+ [ { i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null },
+ { i32, ptr, ptr } { i32 65535, ptr @ctor_noipa, ptr null } ]
diff --git a/llvm/test/Transforms/GlobalOpt/noipa.ll b/llvm/test/Transforms/GlobalOpt/noipa.ll
index 64be84501e63e..16046ca70112a 100644
--- a/llvm/test/Transforms/GlobalOpt/noipa.ll
+++ b/llvm/test/Transforms/GlobalOpt/noipa.ll
@@ -1,15 +1,22 @@
; RUN: opt -passes=globalopt -S < %s | FileCheck %s
-; GlobalOpt changing calling convention of a noipa function.
-; If noipa is working, GlobalOpt should NOT change the CC of @foo,
+; GlobalOpt changing calling convention of a `noipa` function.
+; If `noipa` is working, GlobalOpt should NOT change the CC of @foo,
; because it requires analyzing callers/callees interprocedurally.
-; CHECK: define internal i32 @foo(
-define internal i32 @foo(i32 %x) noipa noinline {
+; CHECK: define internal fastcc i32 @foo(
+define internal i32 @foo(i32 %x) noinline {
+ ret i32 %x
+}
+
+; CHECK: define internal i32 @foo_noipa(
+define internal i32 @foo_noipa(i32 %x) noipa noinline {
ret i32 %x
}
define i32 @bar() {
%r = call i32 @foo(i32 5)
- ret i32 %r
+ %s = call i32 @foo_noipa(i32 5)
+ %res = add i32 %r, %s
+ ret i32 %res
}
diff --git a/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll b/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
index f2aa709afa111..3b899e6f3a344 100644
--- a/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
+++ b/llvm/test/Transforms/GlobalOpt/resolve-static-ifunc-noipa.ll
@@ -4,7 +4,7 @@
@static.ifunc = internal ifunc void (), ptr @static.resolver
-define ptr @static.resolver() noipa {
+define ptr @static.resolver() {
ret ptr @static._Msimd
}
define void @static._Msimd() {
@@ -14,8 +14,16 @@ define void @static.default() {
ret void
}
+ at static_noipa.ifunc = internal ifunc void (), ptr @static_noipa.resolver
+
+define ptr @static_noipa.resolver() noipa {
+ ret ptr @static._Msimd
+}
+
define void @caller() {
- ; CHECK: call void @static.ifunc()
+ ; CHECK: call void @static._Msimd()
call void @static.ifunc()
+ ; CHECK: call void @static_noipa.ifunc()
+ call void @static_noipa.ifunc()
ret void
}
diff --git a/llvm/test/Transforms/Inline/noipa.ll b/llvm/test/Transforms/Inline/noipa.ll
index 31eca22f71d72..d292fcb99bd09 100644
--- a/llvm/test/Transforms/Inline/noipa.ll
+++ b/llvm/test/Transforms/Inline/noipa.ll
@@ -2,7 +2,7 @@
; Ensure `noipa` does _not_ control inlining. The `noipa` attribute controls
; _other_ interprocedural optimisations by affecting the result of
-; `isDefinitionExact` and `hasExactDefinition` checks, but inlining is
+; `isInterposable` and `isDefinitionExact` checks, but inlining is
; controlled separately by the `noinline` attribute.
define internal i32 @noipa(i32 %x) noipa {
diff --git a/llvm/test/Transforms/MergeFunc/noipa.ll b/llvm/test/Transforms/MergeFunc/noipa.ll
index 0c993bfef4e2a..d1fa274f7808f 100644
--- a/llvm/test/Transforms/MergeFunc/noipa.ll
+++ b/llvm/test/Transforms/MergeFunc/noipa.ll
@@ -1,11 +1,12 @@
; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
-; MergeFunctions merging a noipa function with an identical one.
-; If noipa is working, MergeFunctions should NOT merge @foo into @baz
-; (or vice versa), because it inspects the function definitions.
+; MergeFunctions merging a `noipa` function with an identical one.
+; If `noipa` is working, MergeFunctions should NOT merge
+; @foo_noipa into @baz_noipa (or vice versa), because it inspects
+; the function definitions.
-; CHECK: define internal i32 @foo(
-define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
+; CHECK-NOT: define internal i32 @foo(
+define internal i32 @foo(i32 %x, i32 %y) noinline {
%sum = add i32 %x, %y
%mul = mul i32 %sum, %x
%sub = sub i32 %mul, %y
@@ -13,7 +14,23 @@ define internal i32 @foo(i32 %x, i32 %y) noipa noinline {
}
; CHECK: define internal i32 @baz(
-define internal i32 @baz(i32 %x, i32 %y) noipa noinline {
+define internal i32 @baz(i32 %x, i32 %y) noinline {
+ %sum = add i32 %x, %y
+ %mul = mul i32 %sum, %x
+ %sub = sub i32 %mul, %y
+ ret i32 %sub
+}
+
+; CHECK: define internal i32 @foo_noipa(
+define internal i32 @foo_noipa(i32 %x, i32 %y) noipa noinline {
+ %sum = add i32 %x, %y
+ %mul = mul i32 %sum, %x
+ %sub = sub i32 %mul, %y
+ ret i32 %sub
+}
+
+; CHECK: define internal i32 @baz_noipa(
+define internal i32 @baz_noipa(i32 %x, i32 %y) noipa noinline {
%sum = add i32 %x, %y
%mul = mul i32 %sum, %x
%sub = sub i32 %mul, %y
@@ -21,8 +38,16 @@ define internal i32 @baz(i32 %x, i32 %y) noipa noinline {
}
define i32 @bar() {
+ ; CHECK: call i32 @baz(
%r1 = call i32 @foo(i32 1, i32 2)
+ ; CHECK: call i32 @baz(
%r2 = call i32 @baz(i32 3, i32 4)
- %r = add i32 %r1, %r2
- ret i32 %r
+ ; CHECK: call i32 @foo_noipa(
+ %r3 = call i32 @foo_noipa(i32 1, i32 2)
+ ; CHECK: call i32 @baz_noipa(
+ %r4 = call i32 @baz_noipa(i32 3, i32 4)
+ %res1 = add i32 %r1, %r2
+ %res2 = add i32 %r3, %r4
+ %res3 = add i32 %res1, %res2
+ ret i32 %res3
}
diff --git a/llvm/test/Transforms/SCCP/noipa.ll b/llvm/test/Transforms/SCCP/noipa.ll
index 4cae55214665f..f4b29e3ee4096 100644
--- a/llvm/test/Transforms/SCCP/noipa.ll
+++ b/llvm/test/Transforms/SCCP/noipa.ll
@@ -1,16 +1,25 @@
; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
-; IPSCCP constant-propagating through arguments of a noipa function.
-; If noipa is working, IPSCCP should NOT propagate the constant 42 into @foo,
+; IPSCCP constant-propagating through arguments of a `noipa` function.
+; If `noipa` is working, IPSCCP should NOT propagate the constant 42 into @foo,
; because analyzing calls to @foo to determine argument values is IPA.
; CHECK: define internal i32 @foo(i32 %x)
+; CHECK-NEXT: ret i32 poison
+define internal i32 @foo(i32 %x) noinline {
+ ret i32 %x
+}
+
+; CHECK: define internal i32 @foo_noipa(i32 %x)
; CHECK-NEXT: ret i32 %x
-define internal i32 @foo(i32 %x) noipa noinline {
+define internal i32 @foo_noipa(i32 %x) noipa noinline {
ret i32 %x
}
define i32 @bar() {
%r = call i32 @foo(i32 42)
- ret i32 %r
+ %s = call i32 @foo_noipa(i32 42)
+ ; CHECK: %res = add i32 42, %s
+ %res = add i32 %r, %s
+ ret i32 %res
}
More information about the llvm-commits
mailing list