From: Roman Lebedev Date: Thu, 23 Jul 2020 07:51:09 +0000 (+0300) Subject: [Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target X-Git-Tag: llvmorg-13-init~17043 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=469cb724eea198d5ac0608e7828d0f92735dbaa1;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/test/Reduce/remove-all-of-multiple-args.ll b/llvm/test/Reduce/remove-all-of-multiple-args.ll index 4ec0ea4..671a0f6 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 626720f..4e33a6e 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 3c55adf..c23d701 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 Chunks = {{1, Targets}}; - std::set UninterestingChunks; + std::vector ChunksStillConsideredInteresting = {{1, Targets}}; std::unique_ptr 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 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 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 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)