Skip to content

Commit be87321

Browse files
committed
[clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0
This restores the original behaviour before i unadvertedly broke it in e3a4701 and clang/test/Profile/ caught it.
1 parent e3a4701 commit be87321

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,27 +1774,27 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond,
17741774
llvm::MDNode *Weights = nullptr;
17751775
llvm::MDNode *Unpredictable = nullptr;
17761776

1777-
// If optimizing, lower unpredictability/probability knowledge about cond.
1778-
if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
1779-
// If the branch has a condition wrapped by __builtin_unpredictable,
1780-
// create metadata that specifies that the branch is unpredictable.
1781-
if (auto *Call = dyn_cast<CallExpr>(Cond->IgnoreImpCasts())) {
1782-
auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1783-
if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1784-
llvm::MDBuilder MDHelper(getLLVMContext());
1785-
Unpredictable = MDHelper.createUnpredictable();
1786-
}
1777+
// If the branch has a condition wrapped by __builtin_unpredictable,
1778+
// create metadata that specifies that the branch is unpredictable.
1779+
// Don't bother if not optimizing because that metadata would not be used.
1780+
auto *Call = dyn_cast<CallExpr>(Cond->IgnoreImpCasts());
1781+
if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
1782+
auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1783+
if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1784+
llvm::MDBuilder MDHelper(getLLVMContext());
1785+
Unpredictable = MDHelper.createUnpredictable();
17871786
}
1787+
}
17881788

1789-
// If there is a Likelihood knowledge for the cond, lower it.
1790-
llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
1791-
if (CondV != NewCondV)
1792-
CondV = NewCondV;
1793-
else {
1794-
// Otherwise, lower profile counts.
1795-
uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
1796-
Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
1797-
}
1789+
// If there is a Likelihood knowledge for the cond, lower it.
1790+
// Note that if not optimizing this won't emit anything.
1791+
llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
1792+
if (CondV != NewCondV)
1793+
CondV = NewCondV;
1794+
else {
1795+
// Otherwise, lower profile counts. Note that we do this even at -O0.
1796+
uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
1797+
Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
17981798
}
17991799

18001800
Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);

0 commit comments

Comments
 (0)