[llvm] 827f01c - llvm-reduce: Remove okToRemove logic in block reduction

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 23 15:17:14 PDT 2022


Author: Matt Arsenault
Date: 2022-10-23T15:16:55-07:00
New Revision: 827f01c275bec1dc695338719046a12e4a6e096b

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

LOG: llvm-reduce: Remove okToRemove logic in block reduction

This was making decisions based on BBsToDelete, while being
used to determine BBsToDelete which doesn't really work.
Additionally, this is a lot of logic just to avoid deleting
the entry block when we can just skip it.

Added: 
    

Modified: 
    llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
    llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll b/llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
index 4b9555e4a00e..0b373666fafe 100644
--- a/llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
+++ b/llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
@@ -7,7 +7,7 @@
 ; CHECK-INTERESTINGNESS: test
 
 ; CHECK: define void @test() {
-; CHECK-NEXT:   unreachable:
+; CHECK-NEXT:   entry:
 ; CHECK-NEXT:     ret void
 
 define void @test() {

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index 5f70640a3b57..e7883b43b08f 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -102,44 +102,18 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
     }
 }
 
-/// It's OK to add a block to the set of removed blocks if the first
-/// basic block in the function that survives all of the deletions is
-/// a legal entry block. Keep at least one block in a function.
-static bool okToRemove(BasicBlock &Candidate, Function &F,
-                       const DenseSet<BasicBlock *> &BBsToDelete) {
-  size_t NumBlocksDeleted = 0;
-  bool FoundNewEntryBlock = false;
-  for (auto &B : F) {
-    if (&B == &Candidate)
-      continue;
-    if (BBsToDelete.count(&B)) {
-      ++NumBlocksDeleted;
-      continue;
-    }
-    if (!FoundNewEntryBlock) {
-      /// Ok we've found the first block that's not going to be deleted,
-      /// it will be the new entry block -- that's only legal if this
-      /// block has no predecessors among blocks that survive the
-      /// deletions
-      for (BasicBlock *Pred : predecessors(&B)) {
-        if (!BBsToDelete.contains(Pred))
-          return false;
-      }
-      FoundNewEntryBlock = true;
-    }
-  }
-  // Don't delete the last block.
-  return NumBlocksDeleted + 1 < F.size();
-}
-
 /// Removes out-of-chunk arguments from functions, and modifies their calls
 /// accordingly. It also removes allocations of out-of-chunk arguments.
 static void extractBasicBlocksFromModule(Oracle &O, Module &Program) {
   DenseSet<BasicBlock *> BBsToKeep, BBsToDelete;
 
   for (auto &F : Program) {
-    for (auto &BB : F) {
-      if (!okToRemove(BB, F, BBsToDelete) || O.shouldKeep())
+    if (F.empty())
+      continue;
+
+    // Never try to delete the entry block.
+    for (auto &BB : make_range(++F.begin(), F.end())) {
+      if (O.shouldKeep())
         BBsToKeep.insert(&BB);
       else
         BBsToDelete.insert(&BB);


        


More information about the llvm-commits mailing list