diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2021-03-21 23:22:41 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2021-03-21 23:24:27 +0300 |
commit | be8732128029530a0b8671af3a47ce6085039fa2 (patch) | |
tree | 5fd9cc298f84cb5c2e48d3d69be62ce4a6662eeb | |
parent | e3a470162738871bba982416748ae5f5e3572947 (diff) | |
download | llvm-be8732128029530a0b8671af3a47ce6085039fa2.zip llvm-be8732128029530a0b8671af3a47ce6085039fa2.tar.gz llvm-be8732128029530a0b8671af3a47ce6085039fa2.tar.bz2 |
[clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0
This restores the original behaviour before i unadvertedly broke it in
e3a470162738871bba982416748ae5f5e3572947 and clang/test/Profile/ caught it.
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 1c53826..fd70884 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1774,27 +1774,27 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, llvm::MDNode *Weights = nullptr; llvm::MDNode *Unpredictable = nullptr; - // If optimizing, lower unpredictability/probability knowledge about cond. - if (CGM.getCodeGenOpts().OptimizationLevel != 0) { - // If the branch has a condition wrapped by __builtin_unpredictable, - // create metadata that specifies that the branch is unpredictable. - if (auto *Call = dyn_cast<CallExpr>(Cond->IgnoreImpCasts())) { - auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl()); - if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) { - llvm::MDBuilder MDHelper(getLLVMContext()); - Unpredictable = MDHelper.createUnpredictable(); - } + // If the branch has a condition wrapped by __builtin_unpredictable, + // create metadata that specifies that the branch is unpredictable. + // Don't bother if not optimizing because that metadata would not be used. + auto *Call = dyn_cast<CallExpr>(Cond->IgnoreImpCasts()); + if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) { + auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl()); + if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) { + llvm::MDBuilder MDHelper(getLLVMContext()); + Unpredictable = MDHelper.createUnpredictable(); } + } - // If there is a Likelihood knowledge for the cond, lower it. - llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH); - if (CondV != NewCondV) - CondV = NewCondV; - else { - // Otherwise, lower profile counts. - uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount); - Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount); - } + // If there is a Likelihood knowledge for the cond, lower it. + // Note that if not optimizing this won't emit anything. + llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH); + if (CondV != NewCondV) + CondV = NewCondV; + else { + // Otherwise, lower profile counts. Note that we do this even at -O0. + uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount); + Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount); } Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable); |