Skip to content

Commit 8c18c25

Browse files
authored
llvm-reduce: Do not assert if the input is no longer interesting (#133386)
If the interestingness script is flaky, we should not assert. Print a warning, and continue. This could still happen as a result of an llvm-reduce bug, so make a note of that. Add a --skip-verify-interesting-after-counting-chunks option to avoid the extra run of the reduction script, and to silence the warning.
1 parent b2e2950 commit 8c18c25

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

llvm/docs/CommandGuide/llvm-reduce.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ GENERIC OPTIONS
7171

7272
Delta passes to not run, separated by commas. By default, run all delta passes.
7373

74+
.. option::--skip-verify-interesting-after-counting-chunks
75+
76+
Do not validate testcase is interesting after counting chunks. This
77+
will save time by avoiding extra executions of the interestingness
78+
test, but a warning will no longer be printed on flaky reproducers.
79+
7480
.. option:: --starting-granularity-level=<uint>
7581

7682
Number of times to divide chunks prior to first test.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Script to exit 0 on the first run, and non-0 on subsequent
2+
runs. This demonstrates a flaky interestingness test.
3+
"""
4+
import sys
5+
import pathlib
6+
7+
# This will exit 0 the first time the script is run, and fail the second time
8+
pathlib.Path(sys.argv[1]).touch(exist_ok=False)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; Test that there is no assertion if the reproducer is flaky
2+
; RUN: rm -f %t
3+
; 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
4+
5+
; Check no error with -skip-verify-interesting-after-counting-chunks
6+
; RUN: rm -f %t
7+
; 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
8+
9+
; CHECK: warning: input module no longer interesting after counting chunks
10+
; CHECK-NEXT: note: the interestingness test may be flaky, or there may be an llvm-reduce bug
11+
; CHECK-NEXT: note: use -skip-verify-interesting-after-counting-chunks to suppress this warning
12+
13+
; QUIET-NOT: warning
14+
; QUIET-NOT: note
15+
; QUIET-NOT: error
16+
17+
declare void @foo(i32)
18+
19+
define void @func() {
20+
call void @foo(i32 0)
21+
call void @foo(i32 1)
22+
call void @foo(i32 2)
23+
call void @foo(i32 3)
24+
call void @foo(i32 4)
25+
call void @foo(i32 5)
26+
ret void
27+
}

llvm/tools/llvm-reduce/deltas/Delta.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/Support/CommandLine.h"
3030
#include "llvm/Support/MemoryBufferRef.h"
3131
#include "llvm/Support/ThreadPool.h"
32+
#include "llvm/Support/WithColor.h"
3233
#include <fstream>
3334

3435
using namespace llvm;
@@ -40,6 +41,12 @@ static cl::opt<bool> AbortOnInvalidReduction(
4041
cl::desc("Abort if any reduction results in invalid IR"),
4142
cl::cat(LLVMReduceOptions));
4243

44+
static cl::opt<bool> SkipVerifyAfterCountingChunks(
45+
"skip-verify-interesting-after-counting-chunks",
46+
cl::desc("Do not validate testcase is interesting after counting chunks "
47+
"(may speed up reduction)"),
48+
cl::cat(LLVMReduceOptions));
49+
4350
static cl::opt<unsigned int> StartingGranularityLevel(
4451
"starting-granularity-level",
4552
cl::desc("Number of times to divide chunks prior to first test"),
@@ -191,8 +198,16 @@ void llvm::runDeltaPass(TestRunner &Test, ReductionFunc ExtractChunksFromModule,
191198

192199
assert(!Test.getProgram().verify(&errs()) &&
193200
"input module is broken after counting chunks");
194-
assert(Test.getProgram().isReduced(Test) &&
195-
"input module no longer interesting after counting chunks");
201+
202+
if (!SkipVerifyAfterCountingChunks && !Test.getProgram().isReduced(Test)) {
203+
WithColor::warning()
204+
<< "input module no longer interesting after counting chunks\n";
205+
WithColor::note() << "the interestingness test may be flaky, or there "
206+
"may be an llvm-reduce bug\n";
207+
WithColor::note()
208+
<< "use -skip-verify-interesting-after-counting-chunks to "
209+
"suppress this warning\n";
210+
}
196211

197212
#ifndef NDEBUG
198213
// Make sure that the number of chunks does not change as we reduce.

0 commit comments

Comments
 (0)