Skip to content

Commit

Permalink
Add fix for uint32_t overflow in spgo
Browse files Browse the repository at this point in the history
d790649d045433fd02c41f4b2cc0dbb0a40fb7ac
  • Loading branch information
4JustMe4 committed Apr 11, 2024
1 parent 29085bd commit eebb503
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ynd/clang/16/patches/clang/clang-format-patches.patch":"toolchains/ynd/clang/16/patches/clang/clang-format-patches.patch",
"ynd/clang/16/patches/clang/dwarf-emit-namespaces.patch":"toolchains/ynd/clang/16/patches/clang/dwarf-emit-namespaces.patch",
"ynd/clang/16/patches/clang/fix-build.patch":"toolchains/ynd/clang/16/patches/clang/fix-build.patch",
"ynd/clang/16/patches/llvm/spgo-unit32-overflow-fix.patch":"toolchains/ynd/clang/16/patches/llvm/spgo-unit32-overflow-fix.patch",
"ynd/clang/16/patches/llvm/vfs-case-insensitive.patch":"toolchains/ynd/clang/16/patches/llvm/vfs-case-insensitive.patch",
"ynd/gdb/14/ix.sh":"toolchains/ynd/gdb/14/ix.sh",
"ynd/gdb/14/pretty_printers":"devtools/gdb",
Expand Down
1 change: 1 addition & 0 deletions ynd/clang/16/ix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ D149723-optimize-renamer-clang-tidy-check.patch
{% endblock %}

{% block llvm_patches %}
spgo-unit32-overflow-fix.patch
vfs-case-insensitive.patch
{% endblock %}

Expand Down
34 changes: 34 additions & 0 deletions ynd/clang/16/patches/llvm/spgo-unit32-overflow-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- a/lib/Transforms/IPO/SampleProfile.cpp
+++ b/lib/Transforms/IPO/SampleProfile.cpp
@@ -122,6 +122,10 @@ static cl::opt<std::string> SampleProfileFile(
"sample-profile-file", cl::init(""), cl::value_desc("filename"),
cl::desc("Profile file loaded by -sample-profile"), cl::Hidden);

+static cl::opt<bool> DisableSampleFunctionAnnotation(
+ "disable-sample-function-annotation", cl::Hidden, cl::init(false),
+ cl::desc("Disable function calls & invokes anotations"));
+
// The named file contains a set of transformations that may have been applied
// to the symbol names between the program from which the sample data was
// collected and the current program's symbols.
@@ -1616,7 +1620,7 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
for (auto &BI : F) {
BasicBlock *BB = &BI;

- if (BlockWeights[BB]) {
+ if (!DisableSampleFunctionAnnotation && BlockWeights[BB] > 0) {
for (auto &I : *BB) {
if (!isa<CallInst>(I) && !isa<InvokeInst>(I))
continue;
@@ -1715,9 +1719,9 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
// Use uint32_t saturated arithmetic to adjust the incoming weights,
// if needed. Sample counts in profiles are 64-bit unsigned values,
// but internally branch weights are expressed as 32-bit values.
- if (Weight > std::numeric_limits<uint32_t>::max()) {
+ if (Weight >= std::numeric_limits<uint32_t>::max()) {
LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)");
- Weight = std::numeric_limits<uint32_t>::max();
+ Weight = std::numeric_limits<uint32_t>::max() - 1;
}
if (!SampleProfileUseProfi) {
// Weight is added by one to avoid propagation errors introduced by

0 comments on commit eebb503

Please sign in to comment.