From 18da9a0cb35c3849e47625272e477dbc5544e25b Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 18 Dec 2022 17:49:34 +0300 Subject: [PATCH] [llvm-exegesis] Fix 'min' repetition mode in presence of missing measurements 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. --- .../test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s | 1 + llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/llvm/test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s b/llvm/test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s index 9f6a548..2598c04 100644 --- a/llvm/test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s +++ b/llvm/test/tools/llvm-exegesis/X86/latency/latency-CMOV32rr.s @@ -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 diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index c17a29b..459e980 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -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(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)) { -- 2.7.4