[PATCH] D149597: [FS-AFDO] Do not load non-FS profile in MIR loader.
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 9 13:25:34 PDT 2023
hoy updated this revision to Diff 520805.
hoy added a comment.
Updating D149597 <https://reviews.llvm.org/D149597>: [FS-AFDO] Do not load non-FS profile in MIR loader.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149597/new/
https://reviews.llvm.org/D149597
Files:
llvm/include/llvm/ProfileData/SampleProfReader.h
llvm/lib/CodeGen/MIRSampleProfile.cpp
llvm/test/CodeGen/X86/fsafdo_test2.ll
llvm/test/CodeGen/X86/fsafdo_test3.ll
Index: llvm/test/CodeGen/X86/fsafdo_test3.ll
===================================================================
--- llvm/test/CodeGen/X86/fsafdo_test3.ll
+++ llvm/test/CodeGen/X86/fsafdo_test3.ll
@@ -1,7 +1,7 @@
; RUN: llvm-profdata merge --sample -profile-isfs -o %t0.afdo %S/Inputs/fsloader.afdo
-; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false -fs-profile-file=%t0.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV0
+; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false -profile-isfs -fs-profile-file=%t0.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV0
; RUN: llvm-profdata merge --sample -profile-isfs -o %t1.afdo %S/Inputs/fsloader_v1.afdo
-; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true -fs-profile-file=%t1.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV1
+; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true -profile-isfs -fs-profile-file=%t1.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV1
;
;;
;; C source code for the test (compiler at -O3):
Index: llvm/test/CodeGen/X86/fsafdo_test2.ll
===================================================================
--- llvm/test/CodeGen/X86/fsafdo_test2.ll
+++ llvm/test/CodeGen/X86/fsafdo_test2.ll
@@ -1,10 +1,10 @@
; REQUIRES: asserts
; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false < %s | FileCheck %s --check-prefixes=V0,V01
; RUN: llvm-profdata merge --sample -profile-isfs -o %t0.afdo %S/Inputs/fsloader.afdo
-; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false -fs-profile-file=%t0.afdo -show-fs-branchprob -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false < %s 2>&1 | FileCheck %s --check-prefixes=LOADERV0,LOADER
+; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false -profile-isfs -fs-profile-file=%t0.afdo -show-fs-branchprob -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false < %s 2>&1 | FileCheck %s --check-prefixes=LOADERV0,LOADER
; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true < %s | FileCheck %s --check-prefixes=V1,V01
; RUN: llvm-profdata merge --sample -profile-isfs -o %t1.afdo %S/Inputs/fsloader_v1.afdo
-; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true -fs-profile-file=%t1.afdo -show-fs-branchprob -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false < %s 2>&1 | FileCheck %s --check-prefixes=LOADERV1,LOADER
+; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true -profile-isfs -fs-profile-file=%t1.afdo -show-fs-branchprob -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false < %s 2>&1 | FileCheck %s --check-prefixes=LOADERV1,LOADER
;
;;
;; C source code for the test (compiler at -O3):
Index: llvm/lib/CodeGen/MIRSampleProfile.cpp
===================================================================
--- llvm/lib/CodeGen/MIRSampleProfile.cpp
+++ llvm/lib/CodeGen/MIRSampleProfile.cpp
@@ -296,6 +296,15 @@
Reader->setModule(&M);
ProfileIsValid = (Reader->read() == sampleprof_error::success);
+ // Do not load non-FS profiles. A line or probe can get a zero-valued
+ // discriminator at certain pass which could result in accidentally loading
+ // the corresponding base counter in the non-FS profile, while a non-zero
+ // discriminator would end up getting zero samples. This could in turn undo
+ // the sample distribution effort done by previous BFI maintenance and the
+ // probe distribution factor work for pseudo probes.
+ if (!Reader->profileIsFS())
+ return false;
+
// Load pseudo probe descriptors for probe-based function samples.
if (Reader->profileIsProbeBased()) {
ProbeManager = std::make_unique<PseudoProbeManager>(M);
Index: llvm/include/llvm/ProfileData/SampleProfReader.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProfReader.h
+++ llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -483,6 +483,9 @@
/// Whether input profile contains ShouldBeInlined contexts.
bool profileIsPreInlined() const { return ProfileIsPreInlined; }
+ /// Whether input profile is flow-sensitive.
+ bool profileIsFS() const { return ProfileIsFS; }
+
virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() {
return nullptr;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149597.520805.patch
Type: text/x-patch
Size: 5062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230509/4becbefb/attachment.bin>
More information about the llvm-commits
mailing list