[llvm] ba7c79c - [llvm-reduce] Skip chunks that lead to broken modules.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 01:13:29 PDT 2020


Author: Florian Hahn
Date: 2020-08-28T09:08:35+01:00
New Revision: ba7c79cb3a69dd6ec2256afa9913214e63aea0d7

URL: https://github.com/llvm/llvm-project/commit/ba7c79cb3a69dd6ec2256afa9913214e63aea0d7
DIFF: https://github.com/llvm/llvm-project/commit/ba7c79cb3a69dd6ec2256afa9913214e63aea0d7.diff

LOG: [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

Added: 
    

Modified: 
    llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
    llvm/tools/llvm-reduce/deltas/Delta.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
index 0ad801491c6b..6e441c231287 100644
--- a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
+++ b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
@@ -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:

diff  --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index 02ff46dbe2d1..9b0969e93675 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -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)


        


More information about the llvm-commits mailing list