Skip to content

Commit 947b656

Browse files
authored
[PGO] Check that PGOOpt exists before using PGOOpt->ColdOptType (#89139)
This means that the pass is unusable without some sort of profile. We can revisit this decision later if we want to support running this pass without a profile.
1 parent 22ed10d commit 947b656

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11691169
if (EnableSyntheticCounts && !PGOOpt)
11701170
MPM.addPass(SyntheticCountsPropagation());
11711171

1172-
if (EnablePGOForceFunctionAttrs)
1172+
if (EnablePGOForceFunctionAttrs && PGOOpt)
11731173
MPM.addPass(PGOForceFunctionAttrsPass(PGOOpt->ColdOptType));
11741174

11751175
MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/true));

llvm/test/Instrumentation/PGOForceFunctionAttrs/basic.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
; Should be no changes without profile data
77
; RUN: opt < %s -passes=pgo-force-function-attrs -S -pgo-cold-func-opt=minsize | FileCheck %s --check-prefixes=NONE,CHECK
8+
; RUN: opt < %s -passes='default<O2>' -enable-pgo-force-function-attrs -S -pgo-cold-func-opt=minsize | FileCheck %s --check-prefixes=O2
89

910
; NONE-NOT: Function Attrs:
1011
; OPTSIZE: Function Attrs: optsize{{$}}
@@ -37,6 +38,9 @@
3738
; CHECK-NOT: Function Attrs: {{.*}}minsize
3839
; CHECK-NOT: Function Attrs: {{.*}}optnone
3940

41+
; O2: define void @cold_attr(){{.*}} #[[ATTR:[0-9]+]]
42+
; O2-NOT: #[[ATTR]] = {{.*}}minsize
43+
4044
@s = global i32 0
4145

4246
define void @cold() !prof !27 {

0 commit comments

Comments
 (0)