[llvm] 469cb72 - [Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 00:52:01 PDT 2020


Author: Roman Lebedev
Date: 2020-07-23T10:51:46+03:00
New Revision: 469cb724eea198d5ac0608e7828d0f92735dbaa1

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

LOG: [Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target

Summary:
If there was a single target to begin with, because a single target
can only occupy a single chunk, we couldn't increase granularity.
and would immediately give up.

Likewise, if we had multiple targets, if by the end we'd end up with
a single target, we wouldn't finish reducing it, it would always
end up being "interesting"

Reviewers: dblaikie, nickdesaulniers, diegotf

Reviewed By: dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84318

Added: 
    

Modified: 
    llvm/test/Reduce/remove-all-of-multiple-args.ll
    llvm/test/Reduce/remove-single-arg.ll
    llvm/tools/llvm-reduce/deltas/Delta.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/Reduce/remove-all-of-multiple-args.ll b/llvm/test/Reduce/remove-all-of-multiple-args.ll
index 4ec0ea498b5d..671a0f652aaf 100644
--- a/llvm/test/Reduce/remove-all-of-multiple-args.ll
+++ b/llvm/test/Reduce/remove-all-of-multiple-args.ll
@@ -3,7 +3,7 @@
 
 define i32 @t(i32 %a0, i32 %a1, i32 %a2) {
 ; CHECK-ALL-LABEL: @t
-; CHECK-FINAL: (i32 %a0) {
+; CHECK-FINAL: () {
 ;
 ; CHECK-INTERESTINGNESS: ret i32
 ; CHECK-FINAL: ret i32 undef

diff  --git a/llvm/test/Reduce/remove-single-arg.ll b/llvm/test/Reduce/remove-single-arg.ll
index 626720f9361c..4e33a6eebb67 100644
--- a/llvm/test/Reduce/remove-single-arg.ll
+++ b/llvm/test/Reduce/remove-single-arg.ll
@@ -3,7 +3,7 @@
 
 define i32 @t(i32 %a0) {
 ; CHECK-ALL-LABEL: @t
-; CHECK-FINAL: (i32 %a0) {
+; CHECK-FINAL: () {
 ;
 ; CHECK-INTERESTINGNESS: ret i32
 ; CHECK-FINAL: ret i32 42

diff  --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index 3c55adf64db7..c23d70145b69 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -105,26 +105,28 @@ void llvm::runDeltaPass(
     }
   }
 
-  std::vector<Chunk> Chunks = {{1, Targets}};
-  std::set<Chunk> UninterestingChunks;
+  std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
   std::unique_ptr<Module> ReducedProgram;
 
-  if (!increaseGranularity(Chunks)) {
-    errs() << "\nAlready at minimum size. Cannot reduce anymore.\n";
-    return;
-  }
-
+  bool FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity;
   do {
-    UninterestingChunks = {};
-    for (int I = Chunks.size() - 1; I >= 0; --I) {
+    FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = false;
+
+    std::set<Chunk> UninterestingChunks;
+    for (Chunk &ChunkToCheckForUninterestingness :
+         reverse(ChunksStillConsideredInteresting)) {
+      // Take all of ChunksStillConsideredInteresting chunks, except those we've
+      // already deemed uninteresting (UninterestingChunks) but didn't remove
+      // from ChunksStillConsideredInteresting yet, and additionally ignore
+      // ChunkToCheckForUninterestingness chunk.
       std::vector<Chunk> CurrentChunks;
-
-      for (auto C : Chunks)
-        if (!UninterestingChunks.count(C) && C != Chunks[I])
-          CurrentChunks.push_back(C);
-
-      if (CurrentChunks.empty())
-        continue;
+      CurrentChunks.reserve(ChunksStillConsideredInteresting.size() -
+                            UninterestingChunks.size() - 1);
+      copy_if(ChunksStillConsideredInteresting,
+              std::back_inserter(CurrentChunks), [&](const Chunk &C) {
+                return !UninterestingChunks.count(C) &&
+                       C != ChunkToCheckForUninterestingness;
+              });
 
       // Clone module before hacking it up..
       std::unique_ptr<Module> Clone = CloneModule(*Test.getProgram());
@@ -132,28 +134,30 @@ void llvm::runDeltaPass(
       ExtractChunksFromModule(CurrentChunks, Clone.get());
 
       errs() << "Ignoring: ";
-      Chunks[I].print();
-      for (auto C : UninterestingChunks)
+      ChunkToCheckForUninterestingness.print();
+      for (const Chunk &C : UninterestingChunks)
         C.print();
 
-
-
       SmallString<128> CurrentFilepath;
       if (!IsReduced(*Clone, Test, CurrentFilepath)) {
+        // Program became non-reduced, so this chunk appears to be interesting.
         errs() << "\n";
         continue;
       }
 
-      UninterestingChunks.insert(Chunks[I]);
+      FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true;
+      UninterestingChunks.insert(ChunkToCheckForUninterestingness);
       ReducedProgram = std::move(Clone);
       errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
     }
     // Delete uninteresting chunks
-    erase_if(Chunks, [&UninterestingChunks](const Chunk &C) {
-      return UninterestingChunks.count(C);
-    });
-
-  } while (!UninterestingChunks.empty() || increaseGranularity(Chunks));
+    erase_if(ChunksStillConsideredInteresting,
+             [&UninterestingChunks](const Chunk &C) {
+               return UninterestingChunks.count(C);
+             });
+  } while (!ChunksStillConsideredInteresting.empty() &&
+           (FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity ||
+            increaseGranularity(ChunksStillConsideredInteresting)));
 
   // If we reduced the testcase replace it
   if (ReducedProgram)


        


More information about the llvm-commits mailing list