Skip to content

Commit 6841395

Browse files
authored
[PGOForceFunctionAttrs] Don't mark alwaysinline function optnone (#81930)
optnone requires noinline, which is incompatible with alwaysinline.
1 parent 5ff8b30 commit 6841395

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Transforms/Instrumentation/PGOForceFunctionAttrs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ PreservedAnalyses PGOForceFunctionAttrsPass::run(Module &M,
4040
for (Function &F : M) {
4141
if (!shouldRunOnFunction(F, PSI, FAM))
4242
continue;
43-
MadeChange = true;
4443
switch (ColdType) {
4544
case PGOOptions::ColdFuncOpt::Default:
4645
llvm_unreachable("bailed out for default above");
@@ -52,10 +51,14 @@ PreservedAnalyses PGOForceFunctionAttrsPass::run(Module &M,
5251
F.addFnAttr(Attribute::MinSize);
5352
break;
5453
case PGOOptions::ColdFuncOpt::OptNone:
54+
// alwaysinline is incompatible with optnone.
55+
if (F.hasFnAttribute(Attribute::AlwaysInline))
56+
continue;
5557
F.addFnAttr(Attribute::OptimizeNone);
5658
F.addFnAttr(Attribute::NoInline);
5759
break;
5860
}
61+
MadeChange = true;
5962
}
6063
return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all();
6164
}

llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
; CHECK: Function Attrs: noinline optnone{{$}}
2222
; CHECK-NEXT: define void @cold_optnone()
2323

24+
; NONE: Function Attrs: alwaysinline{{$}}
25+
; OPTSIZE: Function Attrs: alwaysinline optsize{{$}}
26+
; MINSIZE: Function Attrs: alwaysinline minsize{{$}}
27+
; OPTNONE: Function Attrs: alwaysinline{{$}}
28+
; CHECK-NEXT: define void @cold_alwaysinline()
29+
2430
; NONE: Function Attrs: cold{{$}}
2531
; OPTSIZE: Function Attrs: cold optsize{{$}}
2632
; MINSIZE: Function Attrs: cold minsize{{$}}
@@ -53,6 +59,11 @@ define void @cold_optnone() noinline optnone !prof !27 {
5359
ret void
5460
}
5561

62+
define void @cold_alwaysinline() alwaysinline !prof !27 {
63+
store i32 1, ptr @s, align 4
64+
ret void
65+
}
66+
5667
define void @cold_attr() cold {
5768
store i32 1, ptr @s, align 4
5869
ret void

0 commit comments

Comments
 (0)