-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NFCI][metadata][clang] Use create{Unlikely,Likely}BranchWeights #89467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFCI][metadata][clang] Use create{Unlikely,Likely}BranchWeights #89467
Conversation
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Vitaly Buka (vitalybuka) ChangesIt does not look like particular value is inportant. Follow up to #89464 Full diff: https://github.com/llvm/llvm-project/pull/89467.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 931cb391342ea2..2b93142f5431a7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3565,9 +3565,8 @@ void CodeGenFunction::EmitCheck(
llvm::BasicBlock *Handlers = createBasicBlock("handler." + CheckName);
llvm::Instruction *Branch = Builder.CreateCondBr(JointCond, Cont, Handlers);
// Give hint that we very much don't expect to execute the handler
- // Value chosen to match UR_NONTAKEN_WEIGHT, see BranchProbabilityInfo.cpp
llvm::MDBuilder MDHelper(getLLVMContext());
- llvm::MDNode *Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
+ llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();
Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
EmitBlock(Handlers);
@@ -3635,7 +3634,7 @@ void CodeGenFunction::EmitCfiSlowPathCheck(
llvm::BranchInst *BI = Builder.CreateCondBr(Cond, Cont, CheckBB);
llvm::MDBuilder MDHelper(getLLVMContext());
- llvm::MDNode *Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
+ llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();
BI->setMetadata(llvm::LLVMContext::MD_prof, Node);
EmitBlock(CheckBB);
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index 1facadd82f1701..67fd885a16d0c5 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -856,8 +856,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) {
llvm::BasicBlock *OrigBB = Branch->getParent();
// Give hint that we very much don't expect to see NaNs.
- // Value chosen to match UR_NONTAKEN_WEIGHT, see BranchProbabilityInfo.cpp
- llvm::MDNode *BrWeight = MDHelper.createBranchWeights(1, (1U << 20) - 1);
+ llvm::MDNode *BrWeight = MDHelper.createUnlikelyBranchWeights();
Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
// Now test the imaginary part and create its branch.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4e7f777ba1d916..ed12009ddf8a66 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2072,7 +2072,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
Builder.CreateCondBr(Builder.CreateICmpEQ(selfValue, Zero),
SelfIsNilBlock, ContBlock,
- MDHelper.createBranchWeights(1, 1 << 20));
+ MDHelper.createUnlikelyBranchWeights());
CGF.EmitBlock(SelfIsNilBlock);
@@ -2107,7 +2107,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
CGF.createBasicBlock("objc_direct_method.class_initialized");
Builder.CreateCondBr(Builder.CreateICmpEQ(isInitialized, Zeros[0]),
notInitializedBlock, initializedBlock,
- MDHelper.createBranchWeights(1, 1 << 20));
+ MDHelper.createUnlikelyBranchWeights());
CGF.EmitBlock(notInitializedBlock);
Builder.SetInsertPoint(notInitializedBlock);
CGF.EmitRuntimeCall(SentInitializeFn, selfValue);
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 042cd5d46da4b2..30f3911a8b03c2 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -4072,7 +4072,7 @@ void CGObjCCommonMac::GenerateDirectMethodPrologue(
llvm::MDBuilder MDHelper(CGM.getLLVMContext());
Builder.CreateCondBr(Builder.CreateICmpEQ(selfValue, Zero), SelfIsNilBlock,
- ContBlock, MDHelper.createBranchWeights(1, 1 << 20));
+ ContBlock, MDHelper.createUnlikelyBranchWeights());
CGF.EmitBlock(SelfIsNilBlock);
|
Created using spr 1.3.4 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…m#89467) It does not look like particular value is inportant. Howere, there is a comment., but the current implementation of `create{Unlikely,Likely}BranchWeights` use the same value. Follow up to llvm#89464
It does not look like particular value is inportant.
Howere, there is a comment., but the current implementation
of
create{Unlikely,Likely}BranchWeights
use the same value.Follow up to #89464