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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
}
11 changes: 11 additions & 0 deletions llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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{{$}}
Expand Down Expand Up @@ -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
Expand Down