[llvm] 1116fa4 - avoid a bug where we remove a BB and then the next one becomes the

John Regehr via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 21:23:25 PDT 2022


Author: John Regehr
Date: 2022-08-02T22:23:12-06:00
New Revision: 1116fa476504a0c3a03b779ce3c020f231b0511c

URL: https://github.com/llvm/llvm-project/commit/1116fa476504a0c3a03b779ce3c020f231b0511c
DIFF: https://github.com/llvm/llvm-project/commit/1116fa476504a0c3a03b779ce3c020f231b0511c.diff

LOG: avoid a bug where we remove a BB and then the next one becomes the
entry block and is illegal due to having more then one predecessor
block

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

Added: 
    

Modified: 
    llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index 520a45ca0c436..5d1b3bab20a1b 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -102,6 +102,19 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
     }
 }
 
+/// A BB is ok to remove if it's not the entry block, or else it is
+/// the entry block but the next block in the function has just one
+/// predecessor -- this property is required because that block is
+/// going to become the new entry block
+static bool okToRemove(BasicBlock &BB) {
+  if (!BB.isEntryBlock())
+    return true;
+  auto F = BB.getParent();
+  auto it = F->begin();
+  ++it;
+  return (it == F->end()) || (*it).hasNPredecessors(1);
+}
+
 /// 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) {
@@ -110,7 +123,7 @@ static void extractBasicBlocksFromModule(Oracle &O, Module &Program) {
   SmallVector<BasicBlock *> BBsToDelete;
   for (auto &F : Program) {
     for (auto &BB : F) {
-      if (O.shouldKeep())
+      if (!okToRemove(BB) || O.shouldKeep())
         BBsToKeep.insert(&BB);
       else {
         BBsToDelete.push_back(&BB);


        


More information about the llvm-commits mailing list