[PATCH] D95269: [SampleFDO] Report error when reading a bad/incompatible profile instead of turning off profile use silently.

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 15:27:13 PST 2021


wmi created this revision.
wmi added reviewers: davidxl, wenlei, hoy.
Herald added a subscriber: hiraditya.
wmi requested review of this revision.
Herald added a project: LLVM.

Currently sample loader pass turns off SampleFDO optimization silently when it sees error in reading the profile. This behavior will defeat the tests which could have caught those bad/incompatible profile problems and let the problem slip to release or production. This patch change the behavior and report an error when reading a bad profile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95269

Files:
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/test/Transforms/SampleProfile/Inputs/bad.extbinary.afdo
  llvm/test/Transforms/SampleProfile/profile-format.ll


Index: llvm/test/Transforms/SampleProfile/profile-format.ll
===================================================================
--- llvm/test/Transforms/SampleProfile/profile-format.ll
+++ llvm/test/Transforms/SampleProfile/profile-format.ll
@@ -6,6 +6,8 @@
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.extbinary.afdo -S | FileCheck %s
 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline.md5extbinary.afdo -S | FileCheck %s
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.md5extbinary.afdo -S | FileCheck %s
+; RUN: not opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad.extbinary.afdo -S 2>&1 | FileCheck %s -check-prefix=BAD-PROFILE
+; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad.extbinary.afdo -S 2>&1 | FileCheck %s -check-prefix=BAD-PROFILE
 
 ; Original C++ test case
 ;
@@ -36,6 +38,9 @@
 ; CHECK: ![[IDX2]] = !{!"branch_weights", i32 5280, i32 113}
 ; CHECK: ![[IDX3]] = !{!"branch_weights", i32 1}
 
+; Check sample-profile phase will report error when it is reading a bad profile.
+; BAD-PROFILE: error: {{.*}}bad.extbinary.afdo: profile reading failed: Malformed sample profile data
+
 ; Function Attrs: nounwind uwtable
 define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !4 {
 entry:
Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -433,9 +433,6 @@
   /// Name of the profile remapping file to load.
   std::string RemappingFilename;
 
-  /// Flag indicating whether the profile input loaded successfully.
-  bool ProfileIsValid = false;
-
   /// Flag indicating if the pass is invoked in ThinLTO compile phase.
   ///
   /// In this phase, in annotation, we should not promote indirect calls.
@@ -1856,7 +1853,12 @@
   }
   Reader = std::move(ReaderOrErr.get());
   Reader->collectFuncsFrom(M);
-  ProfileIsValid = (Reader->read() == sampleprof_error::success);
+  if (std::error_code EC = Reader->read()) {
+    std::string Msg = "profile reading failed: " + EC.message();
+    Ctx.diagnose(DiagnosticInfoSampleProfile(Filename, Msg));
+    return false;
+  }
+
   PSL = Reader->getProfileSymbolList();
 
   // While profile-sample-accurate is on, ignore symbol list.
@@ -1888,8 +1890,6 @@
 
 bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
                                       ProfileSummaryInfo *_PSI, CallGraph *CG) {
-  if (!ProfileIsValid)
-    return false;
   GUIDToFuncNameMapper Mapper(M, *Reader, GUIDToFuncNameMap);
 
   PSI = _PSI;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95269.318666.patch
Type: text/x-patch
Size: 2670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210122/d1672608/attachment.bin>


More information about the llvm-commits mailing list