[llvm] [llvm-profdata] Reject merging single-byte-coverage with count profiles (PR #213175)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 16:58:09 PDT 2026
https://github.com/SharonXSharon created https://github.com/llvm/llvm-project/pull/213175
`llvm-profdata merge` previously silently merged single-byte-coverage profiles with count profiles. We should reject this, because `SingleByteCoverage` will always be set to true in the merged profile, and mess up the PGO pipeline.
`mergeProfileKind` now errors with `cannot merge single-byte-coverage profiles with count (non-coverage) profiles` when exactly one side has `InstrProfKind::SingleByteCoverage` set.
Note: Used AI to generate the code
>From fa0ab71a4dfe81a9840a3ad9b7066a5b4a1878e2 Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin <Stanislav.Mekhanoshin at amd.com>
Date: Thu, 30 Jul 2026 16:29:41 -0700
Subject: [PATCH] [llvm-profdata] Reject merging single-byte-coverage with
count profiles
`llvm-profdata merge` previously silently merged single-byte-coverage
profiles with count profiles. We should reject this, because
`SingleByteCoverage` will always be set to true in the merged profile,
and mess up the PGO pipeline.
`mergeProfileKind` now errors with `cannot merge single-byte-coverage
profiles with count (non-coverage) profiles` when exactly one side has
`InstrProfKind::SingleByteCoverage` set.
Test plan:
Added coverage-vs-count cases to
`llvm/test/tools/llvm-profdata/merge-incompatible.test`, covering both
merge orders and the multi-threaded path.
`./build/bin/llvm-lit -q llvm/test/tools/llvm-profdata/ llvm/test/Transforms/PGOProfile/ llvm/test/tools/llvm-cov/` - 344 tests, all pass.
---
.../llvm-profdata/Inputs/ir-single-byte-coverage.proftext | 7 +++++++
llvm/test/tools/llvm-profdata/merge-incompatible.test | 7 +++++++
2 files changed, 14 insertions(+)
create mode 100644 llvm/test/tools/llvm-profdata/Inputs/ir-single-byte-coverage.proftext
diff --git a/llvm/test/tools/llvm-profdata/Inputs/ir-single-byte-coverage.proftext b/llvm/test/tools/llvm-profdata/Inputs/ir-single-byte-coverage.proftext
new file mode 100644
index 0000000000000..162ff38747b8f
--- /dev/null
+++ b/llvm/test/tools/llvm-profdata/Inputs/ir-single-byte-coverage.proftext
@@ -0,0 +1,7 @@
+:ir
+:single_byte_coverage
+foo2
+29667547796
+2
+1
+1
diff --git a/llvm/test/tools/llvm-profdata/merge-incompatible.test b/llvm/test/tools/llvm-profdata/merge-incompatible.test
index fca72a452069e..e62524baa56cb 100644
--- a/llvm/test/tools/llvm-profdata/merge-incompatible.test
+++ b/llvm/test/tools/llvm-profdata/merge-incompatible.test
@@ -6,3 +6,10 @@ CHECK: ir-basic.proftext: Merge IR generated profile with Clang generated profil
// we do not know which files have incompatible kinds.
RUN: not llvm-profdata merge %p/Inputs/fe-basic.proftext %p/Inputs/ir-basic.proftext --num-threads=2 -o /dev/null 2>&1 | FileCheck %s --check-prefix=THREADS
THREADS: unsupported instrumentation profile format version
+
+// Single-byte-coverage profiles cannot be merged with count profiles, in either
+// order, because the merged profile would be marked as coverage-only.
+RUN: not llvm-profdata merge %p/Inputs/ir-basic.proftext %p/Inputs/ir-single-byte-coverage.proftext -o /dev/null 2>&1 | FileCheck %s --check-prefix=COVERAGE
+RUN: not llvm-profdata merge %p/Inputs/ir-single-byte-coverage.proftext %p/Inputs/ir-basic.proftext -o /dev/null 2>&1 | FileCheck %s --check-prefix=COVERAGE
+RUN: not llvm-profdata merge %p/Inputs/ir-basic.proftext %p/Inputs/ir-single-byte-coverage.proftext --num-threads=2 -o /dev/null 2>&1 | FileCheck %s --check-prefix=COVERAGE
+COVERAGE: cannot merge single-byte-coverage profiles with count (non-coverage) profiles
More information about the llvm-commits
mailing list