aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Reames <preames@rivosinc.com>2024-06-24 16:03:52 +0000
committerPaul Kirth <paulkirth@google.com>2024-06-24 16:03:52 +0000
commitb1f98ba553239ca8ec8026d2f98449df63dd132b (patch)
tree415d46825c93019abe49dcd0f398e575f025a952
parentdbdd78daa50f7c22d9e3493ab7aaf75b7941c72f (diff)
downloadllvm-users/ilovepi/spr/main.llvmprofdatautils-provide-getnumbranchweights-api.zip
llvm-users/ilovepi/spr/main.llvmprofdatautils-provide-getnumbranchweights-api.tar.gz
llvm-users/ilovepi/spr/main.llvmprofdatautils-provide-getnumbranchweights-api.tar.bz2
[𝘀𝗽𝗿] changes introduced through rebaseusers/ilovepi/spr/main.llvmprofdatautils-provide-getnumbranchweights-api
Created using spr 1.3.4 [skip ci]
-rw-r--r--llvm/lib/Transforms/Utils/MisExpect.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp
index aef9d82..7592893 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -151,9 +151,15 @@ void verifyMisExpect(Instruction &I, ArrayRef<uint32_t> RealWeights,
uint64_t TotalBranchWeight =
LikelyBranchWeight + (UnlikelyBranchWeight * NumUnlikelyTargets);
- // Failing this assert means that we have corrupted metadata.
- assert((TotalBranchWeight >= LikelyBranchWeight) && (TotalBranchWeight > 0) &&
- "TotalBranchWeight is less than the Likely branch weight");
+ // FIXME: When we've addressed sample profiling, restore the assertion
+ //
+ // 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.
+ // assert((TotalBranchWeight >= LikelyBranchWeight) && (TotalBranchWeight > 0)
+ // && "TotalBranchWeight is less than the Likely branch weight");
+ 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
@@ -180,13 +186,6 @@ void verifyMisExpect(Instruction &I, ArrayRef<uint32_t> RealWeights,
void checkBackendInstrumentation(Instruction &I,
const ArrayRef<uint32_t> RealWeights) {
- // Backend checking assumes any existing weight comes from an `llvm.expect`
- // intrinsic. However, SampleProfiling + ThinLTO add branch weights multiple
- // times, leading to an invalid assumption in our checking. Backend checks
- // should only operate on branch weights that carry the "!expected" field,
- // since they are guaranteed to be added by the LowerExpectIntrinsic pass.
- if (!hasBranchWeightOrigin(I))
- return;
SmallVector<uint32_t> ExpectedWeights;
if (!extractBranchWeights(I, ExpectedWeights))
return;