[PATCH] D124302: [llvm][misexpect] Replace assertion with early return

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 15:30:40 PDT 2022


paulkirth updated this revision to Diff 424634.
paulkirth added a comment.
Herald added subscribers: ormris, wenlei.

Disable diagnostics when using sample profiling


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124302/new/

https://reviews.llvm.org/D124302

Files:
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/Utils/MisExpect.cpp


Index: llvm/lib/Transforms/Utils/MisExpect.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MisExpect.cpp
+++ llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -185,8 +185,11 @@
   uint64_t TotalBranchWeight =
       LikelyBranchWeight + (UnlikelyBranchWeight * NumUnlikelyTargets);
 
-  assert((TotalBranchWeight >= LikelyBranchWeight) && (TotalBranchWeight > 0) &&
-         "TotalBranchWeight is less than the Likely branch weight");
+  // We cannot calculate branch probability if either of these invariants aren't
+  // met. However, MisExpect diagnostics should not prevent code from compiling,
+  // so we simply forgo emitting diagnostics here, and return early.
+  if ((TotalBranchWeight == 0) || (TotalBranchWeight <= LikelyBranchWeight))
+    return;
 
   // To determine our threshold value we need to obtain the branch probability
   // for the weights added by llvm.expect and use that proportion to calculate
Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -74,7 +74,6 @@
 #include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Utils/CallPromotionUtils.h"
 #include "llvm/Transforms/Utils/Cloning.h"
-#include "llvm/Transforms/Utils/MisExpect.h"
 #include "llvm/Transforms/Utils/SampleProfileInference.h"
 #include "llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h"
 #include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
@@ -1741,7 +1740,10 @@
       }
     }
 
-    misexpect::checkExpectAnnotations(*TI, Weights, /*IsFrontend=*/false);
+    // FIXME: Re-enable for sample profiling after investigating why how the sum
+    // of branch weights can be 0
+    //
+    // misexpect::checkExpectAnnotations(*TI, Weights, /*IsFrontend=*/false);
 
     uint64_t TempWeight;
     // Only set weights if there is at least one non-zero weight.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124302.424634.patch
Type: text/x-patch
Size: 1991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220422/95c9903a/attachment.bin>


More information about the llvm-commits mailing list