[PATCH] D136213: llvm-reduce: Remove okToRemove logic in block reduction
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 16:55:27 PDT 2022
arsenm created this revision.
arsenm added reviewers: regehr, aeubanks, lebedev.ri, fhahn.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
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.
https://reviews.llvm.org/D136213
Files:
llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -102,44 +102,18 @@
}
}
-/// 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);
Index: llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
===================================================================
--- llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
+++ 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() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136213.468745.patch
Type: text/x-patch
Size: 2419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221018/d9a7f7fe/attachment.bin>
More information about the llvm-commits
mailing list