1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[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
This commit is contained in:
Florian Hahn 2020-08-28 08:40:40 +01:00
parent 47182191ac
commit 4cf9e27313
2 changed files with 16 additions and 2 deletions

View File

@ -1,12 +1,15 @@
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
; We cannot change the @alias to undef, because it would result in invalid IR
; (Aliasee should be either GlobalValue or ConstantExpr).
; CHECK-INTERESTINGNESS: @alias =
; CHECK-FINAL: @alias = alias void (i32), void (i32)* undef
; CHECK-FINAL: @alias = alias void (i32), bitcast (void ()* @func to void (i32)*)
@alias = alias void (i32), void (i32)* @func
; CHECK-FINAL-NOT: @func()
; CHECK-FINAL: @func()
define void @func(i32 %arg) {
entry:

View File

@ -14,6 +14,7 @@
#include "Delta.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <fstream>
@ -105,6 +106,9 @@ void llvm::runDeltaPass(
errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
exit(1);
}
assert(!verifyModule(*Program, &errs()) &&
"input module is broken before making changes");
}
std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
@ -135,6 +139,13 @@ void llvm::runDeltaPass(
// Generate Module with only Targets inside Current Chunks
ExtractChunksFromModule(CurrentChunks, Clone.get());
// Some reductions may result in invalid IR. Skip such reductions.
if (verifyModule(*Clone.get(), &errs())) {
errs() << " **** WARNING | reduction resulted in invalid module, "
"skipping\n";
continue;
}
errs() << "Ignoring: ";
ChunkToCheckForUninterestingness.print();
for (const Chunk &C : UninterestingChunks)