Skip to content

Commit ba7c79c

Browse files
committed
[llvm-reduce] Skip chunks that lead to broken modules.
Some reduction passes may create invalid IR. I am not aware of any use case where we would like to proceed reducing invalid IR. Various utils used here, including CloneModule, assume the module to clone is valid and crash otherwise. Ideally, no reduction pass would create invalid IR, but some currently do. ReduceInstructions can be fixed relatively easily (D86210), but others are harder. For example, ReduceBasicBlocks may remove result in invalid PHI nodes. For now, skip the chunks. If we get to the point where all reduction passes result in valid IR, we may want to turn this into an assertion. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D86212
1 parent db1ec04 commit ba7c79c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/test/Reduce/remove-function-bodies-used-in-globals.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
22
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
33

4+
; We cannot change the @alias to undef, because it would result in invalid IR
5+
; (Aliasee should be either GlobalValue or ConstantExpr).
6+
47
; CHECK-INTERESTINGNESS: @alias =
5-
; CHECK-FINAL: @alias = alias void (i32), void (i32)* undef
8+
; CHECK-FINAL: @alias = alias void (i32), bitcast (void ()* @func to void (i32)*)
69

710
@alias = alias void (i32), void (i32)* @func
811

9-
; CHECK-FINAL-NOT: @func()
12+
; CHECK-FINAL: @func()
1013

1114
define void @func(i32 %arg) {
1215
entry:

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "Delta.h"
1616
#include "llvm/ADT/STLExtras.h"
17+
#include "llvm/IR/Verifier.h"
1718
#include "llvm/Support/ToolOutputFile.h"
1819
#include "llvm/Transforms/Utils/Cloning.h"
1920
#include <fstream>
@@ -105,6 +106,9 @@ void llvm::runDeltaPass(
105106
errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
106107
exit(1);
107108
}
109+
110+
assert(!verifyModule(*Program, &errs()) &&
111+
"input module is broken before making changes");
108112
}
109113

110114
std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
@@ -135,6 +139,13 @@ void llvm::runDeltaPass(
135139
// Generate Module with only Targets inside Current Chunks
136140
ExtractChunksFromModule(CurrentChunks, Clone.get());
137141

142+
// Some reductions may result in invalid IR. Skip such reductions.
143+
if (verifyModule(*Clone.get(), &errs())) {
144+
errs() << " **** WARNING | reduction resulted in invalid module, "
145+
"skipping\n";
146+
continue;
147+
}
148+
138149
errs() << "Ignoring: ";
139150
ChunkToCheckForUninterestingness.print();
140151
for (const Chunk &C : UninterestingChunks)

0 commit comments

Comments
 (0)