[llvm] [PGOForceFunctionAttrs] Don't mark alwaysinline function optnone (PR #81930)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 13:58:27 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

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
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

``````````

</details>


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


More information about the llvm-commits mailing list