[PATCH] D86212: [llvm-reduce] Skip chunks that lead to broken modules.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 06:24:17 PDT 2020


fhahn created this revision.
fhahn added reviewers: lebedev.ri, dblaikie.
Herald added a project: LLVM.
fhahn requested review of this revision.

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 <https://reviews.llvm.org/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86212

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


Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ 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>
@@ -103,6 +104,9 @@
       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}};
@@ -133,6 +137,14 @@
       // Generate Module with only Targets inside Current Chunks
       ExtractChunksFromModule(CurrentChunks, Clone.get());
 
+      // Some reductions may result in invalid IR. Skip those chunks, to ensure
+      // the program stays valid.
+      if (verifyModule(*Clone.get(), &errs())) {
+        errs() << " **** WARNING | reduction resulted in invalid module, "
+                  "skipping\n";
+        continue;
+      }
+
       errs() << "Ignoring: ";
       ChunkToCheckForUninterestingness.print();
       for (const Chunk &C : UninterestingChunks)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86212.286547.patch
Type: text/x-patch
Size: 1309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200819/a08e9ff5/attachment.bin>


More information about the llvm-commits mailing list