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

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 16 11:33:49 PST 2024


Author: Arthur Eubanks
Date: 2024-02-16T11:33:45-08:00
New Revision: 6841395953e64002c836a724e5429358554385a3

URL: https://github.com/llvm/llvm-project/commit/6841395953e64002c836a724e5429358554385a3
DIFF: https://github.com/llvm/llvm-project/commit/6841395953e64002c836a724e5429358554385a3.diff

LOG: [PGOForceFunctionAttrs] Don't mark alwaysinline function optnone (#81930)

optnone requires noinline, which is incompatible with alwaysinline.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp
    llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll

Removed: 
    


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