diff options
author | Manman Ren <mren@apple.com> | 2012-09-17 23:07:43 +0000 |
---|---|---|
committer | Manman Ren <mren@apple.com> | 2012-09-17 23:07:43 +0000 |
commit | ce48ea7e255ae343d8186fbeed397cf6961e2d5a (patch) | |
tree | 5b5eb723d155abcecf71412045f50cedf6db1808 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 3e5546add7eddddb2533c06de6594eed6d611682 (diff) | |
download | bcm5719-llvm-ce48ea7e255ae343d8186fbeed397cf6961e2d5a.tar.gz bcm5719-llvm-ce48ea7e255ae343d8186fbeed397cf6961e2d5a.zip |
PGO: preserve branch-weight metadata when simplifying Switch
Hanlde the case when we split the default edge if the default target has "icmp"
and unconditinal branch.
llvm-svn: 164076
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 67cb8f59ba6..1316b859e8c 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2425,6 +2425,21 @@ static bool TryToSimplifyUncondBranchWithICmpInIt(ICmpInst *ICI, // the switch to the merge point on the compared value. BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "switch.edge", BB->getParent(), BB); + SmallVector<uint64_t, 8> Weights; + bool HasWeights = HasBranchWeights(SI); + if (HasWeights) { + GetBranchWeights(SI, Weights); + if (Weights.size() == 1 + SI->getNumCases()) { + // Split weight for default case to case for "Cst". + Weights[0] = (Weights[0]+1) >> 1; + Weights.push_back(Weights[0]); + + SmallVector<uint32_t, 8> MDWeights(Weights.begin(), Weights.end()); + SI->setMetadata(LLVMContext::MD_prof, + MDBuilder(SI->getContext()). + createBranchWeights(MDWeights)); + } + } SI->addCase(Cst, NewBB); // NewBB branches to the phi block, add the uncond branch and the phi entry. |