Skip to content

Commit 16b2387

Browse files
[llvm-exegesis] Fix snippet value scaling (#77226)
Currently, BenchmarkRunner scales the per snippet counters by multiplying the raw counter values by the number of instructions (casted to a double) divided by the minimum number of instructions. This is incorrect for the loop repetition mode for snippets that don't fit a whole number of times into the minimum instruction count. For example, with 3 instructions in the snippet and the minimum number of instructions set to 4, the loop repetitor will execute a total of six instructions, but BenchmarkRunner will scale the raw count by 3/4 instead of 3/6=1/2. This will also be incorrect for the duplicate snippet repetitor after #77224. This patch fixes this behavior by dividing the raw count by the ceiling of the number of repetitions divided by the instruction count.
1 parent 3973955 commit 16b2387

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <cmath>
910
#include <memory>
1011
#include <string>
1112

@@ -615,9 +616,9 @@ std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
615616
// Scale the measurements by instruction.
616617
BM.PerInstructionValue /= BenchmarkResult.NumRepetitions;
617618
// Scale the measurements by snippet.
618-
BM.PerSnippetValue *=
619-
static_cast<double>(BenchmarkResult.Key.Instructions.size()) /
620-
BenchmarkResult.NumRepetitions;
619+
BM.PerSnippetValue /=
620+
std::ceil(BenchmarkResult.NumRepetitions /
621+
static_cast<double>(BenchmarkResult.Key.Instructions.size()));
621622
}
622623
BenchmarkResult.Measurements = std::move(*NewMeasurements);
623624

0 commit comments

Comments
 (0)