Skip to content

[PGOForceFunctionAttrs] Don't mark alwaysinline function optnone #81930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

aeubanks
Copy link
Contributor

optnone requires noinline, which is incompatible with alwaysinline.

optnone requires noinline, which is incompatible with alwaysinline.
@llvmbot llvmbot added PGO Profile Guided Optimizations llvm:transforms labels Feb 15, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 15, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-pgo

Author: Arthur Eubanks (aeubanks)

Changes

optnone requires noinline, which is incompatible with alwaysinline.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp (+4-1)
  • (modified) llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll (+11)
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

@aeubanks aeubanks merged commit 6841395 into llvm:main Feb 16, 2024
@aeubanks aeubanks deleted the fix-pgo branch February 16, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:transforms PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants