diff --git a/llvm/docs/CommandGuide/llvm-reduce.rst b/llvm/docs/CommandGuide/llvm-reduce.rst index d23d39b6126b6..2670668af6cca 100644 --- a/llvm/docs/CommandGuide/llvm-reduce.rst +++ b/llvm/docs/CommandGuide/llvm-reduce.rst @@ -71,6 +71,12 @@ GENERIC OPTIONS Delta passes to not run, separated by commas. By default, run all delta passes. +.. option::--skip-verify-interesting-after-counting-chunks + + Do not validate testcase is interesting after counting chunks. This + will save time by avoiding extra executions of the interestingness + test, but a warning will no longer be printed on flaky reproducers. + .. option:: --starting-granularity-level= Number of times to divide chunks prior to first test. diff --git a/llvm/test/tools/llvm-reduce/Inputs/flaky-test.py b/llvm/test/tools/llvm-reduce/Inputs/flaky-test.py new file mode 100644 index 0000000000000..0d85616a43b4c --- /dev/null +++ b/llvm/test/tools/llvm-reduce/Inputs/flaky-test.py @@ -0,0 +1,8 @@ +"""Script to exit 0 on the first run, and non-0 on subsequent +runs. This demonstrates a flaky interestingness test. +""" +import sys +import pathlib + +# This will exit 0 the first time the script is run, and fail the second time +pathlib.Path(sys.argv[1]).touch(exist_ok=False) diff --git a/llvm/test/tools/llvm-reduce/flaky-interestingness.ll b/llvm/test/tools/llvm-reduce/flaky-interestingness.ll new file mode 100644 index 0000000000000..241331e4f655e --- /dev/null +++ b/llvm/test/tools/llvm-reduce/flaky-interestingness.ll @@ -0,0 +1,27 @@ +; Test that there is no assertion if the reproducer is flaky +; RUN: rm -f %t +; RUN: llvm-reduce -j=1 --delta-passes=instructions --test %python --test-arg %p/Inputs/flaky-test.py --test-arg %t %s -o /dev/null 2>&1 | FileCheck %s + +; Check no error with -skip-verify-interesting-after-counting-chunks +; RUN: rm -f %t +; RUN: llvm-reduce -j=1 -skip-verify-interesting-after-counting-chunks --delta-passes=instructions --test %python --test-arg %p/Inputs/flaky-test.py --test-arg %t %s -o /dev/null 2>&1 | FileCheck --allow-empty -check-prefix=QUIET %s + +; CHECK: warning: input module no longer interesting after counting chunks +; CHECK-NEXT: note: the interestingness test may be flaky, or there may be an llvm-reduce bug +; CHECK-NEXT: note: use -skip-verify-interesting-after-counting-chunks to suppress this warning + +; QUIET-NOT: warning +; QUIET-NOT: note +; QUIET-NOT: error + +declare void @foo(i32) + +define void @func() { + call void @foo(i32 0) + call void @foo(i32 1) + call void @foo(i32 2) + call void @foo(i32 3) + call void @foo(i32 4) + call void @foo(i32 5) + ret void +} diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp index 1ae641389ade1..6f84b6c09d145 100644 --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/ThreadPool.h" +#include "llvm/Support/WithColor.h" #include using namespace llvm; @@ -40,6 +41,12 @@ static cl::opt AbortOnInvalidReduction( cl::desc("Abort if any reduction results in invalid IR"), cl::cat(LLVMReduceOptions)); +static cl::opt SkipVerifyAfterCountingChunks( + "skip-verify-interesting-after-counting-chunks", + cl::desc("Do not validate testcase is interesting after counting chunks " + "(may speed up reduction)"), + cl::cat(LLVMReduceOptions)); + static cl::opt StartingGranularityLevel( "starting-granularity-level", cl::desc("Number of times to divide chunks prior to first test"), @@ -191,8 +198,16 @@ void llvm::runDeltaPass(TestRunner &Test, ReductionFunc ExtractChunksFromModule, assert(!Test.getProgram().verify(&errs()) && "input module is broken after counting chunks"); - assert(Test.getProgram().isReduced(Test) && - "input module no longer interesting after counting chunks"); + + if (!SkipVerifyAfterCountingChunks && !Test.getProgram().isReduced(Test)) { + WithColor::warning() + << "input module no longer interesting after counting chunks\n"; + WithColor::note() << "the interestingness test may be flaky, or there " + "may be an llvm-reduce bug\n"; + WithColor::note() + << "use -skip-verify-interesting-after-counting-chunks to " + "suppress this warning\n"; + } #ifndef NDEBUG // Make sure that the number of chunks does not change as we reduce.