[PATCH] D125766: [llvm-reduce] improve bb removal
Markus Lavin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 24 00:53:48 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb8e02325ffc: llvm-reduce: improve basic-blocks removal pass (authored by markus).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125766/new/
https://reviews.llvm.org/D125766
Files:
llvm/test/tools/llvm-reduce/remove-bbs-sequence.ll
llvm/test/tools/llvm-reduce/remove-bbs-sequence.py
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
@@ -47,6 +47,19 @@
Term->eraseFromParent();
if (ChunkSuccessors.empty()) {
+ // Scan forward in BB list to try find a block that is kept.
+ Function &F = *BB.getParent();
+ Function::iterator FI = BB.getIterator();
+ FI++;
+ while (FI != F.end()) {
+ auto &FIB = *FI;
+ if (BBsToKeep.count(&FIB) && !isa<PHINode>(FIB.begin())) {
+ BranchInst::Create(&FIB, &BB);
+ return;
+ }
+ FI++;
+ }
+ // If that fails then resort to replacing with a ret.
auto *FnRetTy = BB.getParent()->getReturnType();
ReturnInst::Create(BB.getContext(),
FnRetTy->isVoidTy() ? nullptr : UndefValue::get(FnRetTy),
Index: llvm/test/tools/llvm-reduce/remove-bbs-sequence.py
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-bbs-sequence.py
@@ -0,0 +1,15 @@
+import subprocess
+import sys
+
+opt = subprocess.run( [ 'opt', '-passes=print<loops>','-disable-output', sys.argv[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE )
+
+stdout = opt.stdout.decode()
+
+pattern = 'Loop at depth 1 containing'
+
+if (pattern in opt.stderr.decode()):
+ print('This is interesting!')
+ sys.exit(0)
+else:
+ print('This is NOT interesting!')
+ sys.exit(1)
Index: llvm/test/tools/llvm-reduce/remove-bbs-sequence.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-bbs-sequence.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-reduce --delta-passes=basic-blocks --test %python --test-arg %p/remove-bbs-sequence.py %s -o %t
+; RUN: cat %t | FileCheck %s
+
+; The interestingness test is that the CFG contains a loop. Verify that the
+; unnecessary bb2 and bb3 are removed while still maintaining a loop.
+
+define void @main() {
+ bb0:
+ br label %bb1
+ bb1:
+ br label %bb2
+ bb2:
+ br label %bb3
+ bb3:
+ %phi = phi i32 [ undef, %bb2 ]
+ br label %bb4
+ bb4:
+ br label %bb1
+}
+
+; CHECK:define void @main() {
+; CHECK-NEXT: bb0:
+; CHECK-NEXT: br label %bb1
+; CHECK-EMPTY:
+; CHECK-NEXT: bb1:
+; CHECK-NEXT: br label %bb4
+; CHECK-EMPTY:
+; CHECK-NEXT: bb4:
+; CHECK-NEXT: br label %bb1
+; CHECK-NEXT:}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125766.431606.patch
Type: text/x-patch
Size: 2460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220524/10c530f0/attachment.bin>
More information about the llvm-commits
mailing list