[llvm] llvm-reduce: Use simpleSimplifyCFG in block reduction (PR #135028)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 07:14:25 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/135028

Use the more targeted method of pruning newly dead blocks.

>From 36e120dc795025a80a4b5a04d8a7186ec58ab61f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 9 Apr 2025 16:10:50 +0800
Subject: [PATCH] llvm-reduce: Use simpleSimplifyCFG in block reduction

Use the more targeted method of pruning newly dead blocks.
---
 .../tools/llvm-reduce/remove-bb-switch-default.ll |  1 +
 .../llvm-reduce/deltas/ReduceBasicBlocks.cpp      | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/llvm/test/tools/llvm-reduce/remove-bb-switch-default.ll b/llvm/test/tools/llvm-reduce/remove-bb-switch-default.ll
index 34a2286afad4e..b509d1181f74d 100644
--- a/llvm/test/tools/llvm-reduce/remove-bb-switch-default.ll
+++ b/llvm/test/tools/llvm-reduce/remove-bb-switch-default.ll
@@ -16,6 +16,7 @@
 ; RESULT0-NEXT: br i1 %arg0, label %bb1, label %bb2
 
 ; RESULT0: bb1:
+; RESULT0: %bb1.phi = phi i32 [ %bb.load, %bb ], [ %bb.load, %bb2 ], [ %bb.load, %bb2 ]
 ; RESULT0-NEXT: store i32 1, ptr null, align 4
 ; RESULT0-NEXT: ret void
 
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index 5656fdda764a4..a7767b5e4233d 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -31,9 +31,11 @@
 
 using namespace llvm;
 
+using BlockSet = SetVector<BasicBlock *>;
+
 /// Replaces BB Terminator with one that only contains Chunk BBs
 static void replaceBranchTerminator(BasicBlock &BB,
-                                    const DenseSet<BasicBlock *> &BBsToDelete) {
+                                    const BlockSet &BBsToDelete) {
   auto *Term = BB.getTerminator();
   std::vector<BasicBlock *> ChunkSuccessors;
   for (auto *Succ : successors(&BB)) {
@@ -104,9 +106,8 @@ static void replaceBranchTerminator(BasicBlock &BB,
 /// Removes uninteresting BBs from switch, if the default case ends up being
 /// uninteresting, the switch is replaced with a void return (since it has to be
 /// replace with something)
-static void
-removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
-                                 const DenseSet<BasicBlock *> &BBsToDelete) {
+static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
+                                             const BlockSet &BBsToDelete) {
   for (int I = 0, E = SwInst.getNumCases(); I != E; ++I) {
     auto Case = SwInst.case_begin() + I;
     if (BBsToDelete.count(Case->getCaseSuccessor())) {
@@ -142,7 +143,8 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
 /// Removes out-of-chunk arguments from functions, and modifies their calls
 /// accordingly. It also removes allocations of out-of-chunk arguments.
 void llvm::reduceBasicBlocksDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
-  DenseSet<BasicBlock *> BBsToDelete;
+  BlockSet BBsToDelete;
+
   df_iterator_default_set<BasicBlock *> Reachable;
 
   for (auto &F : WorkItem.getModule()) {
@@ -183,7 +185,8 @@ void llvm::reduceBasicBlocksDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
     // Cleanup any blocks that are now dead after eliminating this set. This
     // will likely be larger than the number of blocks the oracle told us to
     // delete.
-    EliminateUnreachableBlocks(F);
+    simpleSimplifyCFG(F, BBsToDelete.getArrayRef());
+
     BBsToDelete.clear();
   }
 }



More information about the llvm-commits mailing list