diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp --- a/llvm/lib/IR/ProfDataUtils.cpp +++ b/llvm/lib/IR/ProfDataUtils.cpp @@ -114,7 +114,8 @@ MDNode *getValidBranchWeightMDNode(const Instruction &I) { auto *ProfileData = getBranchWeightMDNode(I); - if (ProfileData && ProfileData->getNumOperands() == 1 + I.getNumSuccessors()) + if (ProfileData && + ProfileData->getNumOperands() == WeightsIdx + I.getNumSuccessors()) return ProfileData; return nullptr; } @@ -128,7 +129,7 @@ bool extractBranchWeights(const Instruction &I, SmallVectorImpl &Weights) { - auto *ProfileData = I.getMetadata(LLVMContext::MD_prof); + MDNode *ProfileData = I.getMetadata(LLVMContext::MD_prof); return extractBranchWeights(ProfileData, Weights); } @@ -140,7 +141,7 @@ "switch"); SmallVector Weights; - auto *ProfileData = I.getMetadata(LLVMContext::MD_prof); + MDNode *ProfileData = I.getMetadata(LLVMContext::MD_prof); if (!extractBranchWeights(ProfileData, Weights)) return false; diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp --- a/llvm/lib/Transforms/Utils/MisExpect.cpp +++ b/llvm/lib/Transforms/Utils/MisExpect.cpp @@ -80,8 +80,8 @@ Instruction *getInstCondition(Instruction *I) { assert(I != nullptr && "MisExpect target Instruction cannot be nullptr"); Instruction *Ret = nullptr; - if (auto *B = dyn_cast(I)) { - Ret = dyn_cast(B->getCondition()); + if (auto *BI = dyn_cast(I)) { + Ret = dyn_cast(BI->getCondition()); } // TODO: Find a way to resolve condition location for switches // Using the condition of the switch seems to often resolve to an earlier @@ -92,8 +92,8 @@ // for branch instructions, then we should remove this function and directly // use the instruction // - else if (auto *S = dyn_cast(I)) { - Ret = dyn_cast(S->getCondition()); + else if (auto *SI = dyn_cast(I)) { + Ret = dyn_cast(SI->getCondition()); } return Ret ? Ret : I; } @@ -163,13 +163,13 @@ // 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 // our threshold based on the collected profile data. - auto LikelyProbablilty = BranchProbability::getBranchProbability( + BranchProbability LikelyProbablilty = BranchProbability::getBranchProbability( LikelyBranchWeight, TotalBranchWeight); uint64_t ScaledThreshold = LikelyProbablilty.scale(RealWeightsTotal); // clamp tolerance range to [0, 100) - auto Tolerance = getMisExpectTolerance(I.getContext()); + uint32_t Tolerance = getMisExpectTolerance(I.getContext()); Tolerance = std::clamp(Tolerance, 0u, 99u); // Allow users to relax checking by N% i.e., if they use a 5% tolerance,