[llvm] [PGOForceFunctionAttrs] Don't mark alwaysinline function optnone (PR #81930)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 13:58:01 PST 2024
https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/81930
optnone requires noinline, which is incompatible with alwaysinline.
>From a7980e972933739c2a860e3b8333265f14caf373 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Thu, 15 Feb 2024 21:53:32 +0000
Subject: [PATCH] [PGOForceFunctionAttrs] Don't mark alwaysinline function
optnone
optnone requires noinline, which is incompatible with alwaysinline.
---
.../Instrumentation/PGOForceFunctionAttrs.cpp | 5 ++++-
.../Instrumentation/PGOForceFunctionAttrs/basic.ll | 11 +++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp b/llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp
index c0ebdd7ed88635..d93b5e5ac90356 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp
@@ -40,7 +40,6 @@ PreservedAnalyses PGOForceFunctionAttrsPass::run(Module &M,
for (Function &F : M) {
if (!shouldRunOnFunction(F, PSI, FAM))
continue;
- MadeChange = true;
switch (ColdType) {
case PGOOptions::ColdFuncOpt::Default:
llvm_unreachable("bailed out for default above");
@@ -52,10 +51,14 @@ PreservedAnalyses PGOForceFunctionAttrsPass::run(Module &M,
F.addFnAttr(Attribute::MinSize);
break;
case PGOOptions::ColdFuncOpt::OptNone:
+ // alwaysinline is incompatible with optnone.
+ if (F.hasFnAttribute(Attribute::AlwaysInline))
+ continue;
F.addFnAttr(Attribute::OptimizeNone);
F.addFnAttr(Attribute::NoInline);
break;
}
+ MadeChange = true;
}
return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
diff --git a/llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll b/llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll
index 29ebc0366040e1..1da047176e99ad 100644
--- a/llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll
+++ b/llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll
@@ -21,6 +21,12 @@
; CHECK: Function Attrs: noinline optnone{{$}}
; CHECK-NEXT: define void @cold_optnone()
+; NONE: Function Attrs: alwaysinline{{$}}
+; OPTSIZE: Function Attrs: alwaysinline optsize{{$}}
+; MINSIZE: Function Attrs: alwaysinline minsize{{$}}
+; OPTNONE: Function Attrs: alwaysinline{{$}}
+; CHECK-NEXT: define void @cold_alwaysinline()
+
; NONE: Function Attrs: cold{{$}}
; OPTSIZE: Function Attrs: cold optsize{{$}}
; MINSIZE: Function Attrs: cold minsize{{$}}
@@ -53,6 +59,11 @@ define void @cold_optnone() noinline optnone !prof !27 {
ret void
}
+define void @cold_alwaysinline() alwaysinline !prof !27 {
+ store i32 1, ptr @s, align 4
+ ret void
+}
+
define void @cold_attr() cold {
store i32 1, ptr @s, align 4
ret void
More information about the llvm-commits
mailing list