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

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba7c79cb3a69: [llvm-reduce] Skip chunks that lead to broken modules. (authored by fhahn).

Changed prior to commit:
  https://reviews.llvm.org/D86212?vs=286547&id=288546#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86212/new/

https://reviews.llvm.org/D86212

Files:
  llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
  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>
@@ -105,6 +106,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}};
@@ -135,6 +139,13 @@
       // 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)
Index: llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
===================================================================
--- llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
+++ 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86212.288546.patch
Type: text/x-patch
Size: 2222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200828/483115c4/attachment.bin>


More information about the llvm-commits mailing list