diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-04-04 02:48:51 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-04-04 02:48:51 +0000 |
| commit | f3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7 (patch) | |
| tree | c218bc20650b5f7f7d4f26c1fa4870c56aaab52c /clang/lib/CodeGen/CodeGenPGO.cpp | |
| parent | 08d57b951c2ff9c5f710d4f66e71393cee573733 (diff) | |
| download | bcm5719-llvm-f3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7.tar.gz bcm5719-llvm-f3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7.zip | |
CodeGen: Don't create branch weight metadata from empty profiles
If all of our weights are zero when calculating branch weights, it
means we haven't profiled the code in question. Avoid creating a
metadata node that says all branches are equally likely in this case.
The test also checks constructs that hit the other createBranchWeights
overload. These were already working.
llvm-svn: 205606
Diffstat (limited to 'clang/lib/CodeGen/CodeGenPGO.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenPGO.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index ac6b7bca40f..935724f59f5 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1004,9 +1004,13 @@ llvm::MDNode *CodeGenPGO::createBranchWeights(ArrayRef<uint64_t> Weights) { if (Weights.size() < 2) return nullptr; + // Check for empty weights. + uint64_t MaxWeight = *std::max_element(Weights.begin(), Weights.end()); + if (MaxWeight == 0) + return nullptr; + // Calculate how to scale down to 32-bits. - uint64_t Scale = calculateWeightScale(*std::max_element(Weights.begin(), - Weights.end())); + uint64_t Scale = calculateWeightScale(MaxWeight); SmallVector<uint32_t, 16> ScaledWeights; ScaledWeights.reserve(Weights.size()); |

