From b1f98ba553239ca8ec8026d2f98449df63dd132b Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 24 Jun 2024 16:03:52 +0000 Subject: =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20changes=20intr?= =?UTF-8?q?oduced=20through=20rebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 [skip ci] --- llvm/lib/Transforms/Utils/MisExpect.cpp | 19 +++++++++---------- 1 file 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 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 RealWeights, void checkBackendInstrumentation(Instruction &I, const ArrayRef 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 ExpectedWeights; if (!extractBranchWeights(I, ExpectedWeights)) return; -- cgit v1.1