@@ -1774,27 +1774,27 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond,
1774
1774
llvm::MDNode *Weights = nullptr ;
1775
1775
llvm::MDNode *Unpredictable = nullptr ;
1776
1776
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 ();
1787
1786
}
1787
+ }
1788
1788
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);
1798
1798
}
1799
1799
1800
1800
Builder.CreateCondBr (CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
0 commit comments