[llvm-exegesis] Fix 'min' repetition mode in presence of missing measurements
authorRoman Lebedev <lebedev.ri@gmail.com>
Sun, 18 Dec 2022 14:49:34 +0000 (17:49 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sun, 18 Dec 2022 14:52:04 +0000 (17:52 +0300)
This was a regression from 17e202424c021fd903950fec7a8b6cca2d83abce.
Previously we'd gracefully handle missing measurements,
but that handling got accidentally lost during the code move,
and we'd assert.

What we want to do, is to discard all measurements (from all repetitors
in a given config) if any of them failed, but do append the snippet,
and do emit the empty measurement.

llvm/test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s
llvm/tools/llvm-exegesis/llvm-exegesis.cpp

index 9f6a548..2598c04 100644 (file)
@@ -1,5 +1,6 @@
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --skip-measurements -opcode-name=CMOV32rr -repetition-mode=duplicate | FileCheck %s
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --skip-measurements -opcode-name=CMOV32rr -repetition-mode=loop | FileCheck %s
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --skip-measurements -opcode-name=CMOV32rr -repetition-mode=min | FileCheck %s
 
 CHECK:      ---
 CHECK-NEXT: mode: latency
index c17a29b..459e980 100644 (file)
@@ -348,14 +348,21 @@ static void runBenchmarkConfigurations(
     }
     InstructionBenchmark &Result = AllResults.front();
 
+    // If any of our measurements failed, pretend they all have failed.
+    if (AllResults.size() > 1 &&
+        any_of(AllResults, [](const InstructionBenchmark &R) {
+          return R.Measurements.empty();
+        }))
+      Result.Measurements.clear();
+
     if (RepetitionMode == InstructionBenchmark::RepetitionModeE::AggregateMin) {
-      assert(!Result.Measurements.empty() &&
-             "We're in an 'min' repetition mode, and need to aggregate new "
-             "result to the existing result.");
       for (const InstructionBenchmark &OtherResult :
            ArrayRef<InstructionBenchmark>(AllResults).drop_front()) {
         llvm::append_range(Result.AssembledSnippet,
                            OtherResult.AssembledSnippet);
+        // Aggregate measurements, but only iff all measurements succeeded.
+        if (Result.Measurements.empty())
+          continue;
         assert(OtherResult.Measurements.size() == Result.Measurements.size() &&
                "Expected to have identical number of measurements.");
         for (auto I : zip(Result.Measurements, OtherResult.Measurements)) {