[PATCH] D113486: [llvm-reduce] Fix invalid reduction in basic-blocks delta pass

Dwight Guth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 10:39:33 PST 2021


dwightguth updated this revision to Diff 385887.
dwightguth added a comment.

fix commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113486/new/

https://reviews.llvm.org/D113486

Files:
  llvm/test/tools/llvm-reduce/remove-bbs-comdat.ll
  llvm/test/tools/llvm-reduce/remove-bbs-entry.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
@@ -126,7 +126,15 @@
     // Instructions might be referenced in other BBs
     for (auto &I : *BB)
       I.replaceAllUsesWith(UndefValue::get(I.getType()));
-    BB->eraseFromParent();
+    if (BB->getParent()->size() == 1) {
+      // this is the last basic block of the function, thus we must also make
+      // sure to remove comdat and set linkage to external
+      auto F = BB->getParent();
+      F->deleteBody();
+      F->setComdat(nullptr);
+    } else {
+      BB->eraseFromParent();
+    }
   }
 }
 
Index: llvm/test/tools/llvm-reduce/remove-bbs-entry.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-bbs-entry.ll
@@ -0,0 +1,18 @@
+; Test that llvm-reduce correctly removes the entry block of functions for
+; linkages other than external and weak.
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: cat %t | FileCheck %s
+
+; CHECK-INTERESTINGNESS: interesting1:
+
+; CHECK-NOT: uninteresting
+define linkonce_odr i32 @foo() {
+uninteresting:
+  ret i32 0
+}
+
+define i32 @main(i1 %c) {
+interesting1:
+  ret i32 0
+}
Index: llvm/test/tools/llvm-reduce/remove-bbs-comdat.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-bbs-comdat.ll
@@ -0,0 +1,21 @@
+; RUN: llvm-reduce --delta-passes=basic-blocks --abort-on-invalid-reduction --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
+
+; CHECK-FINAL-NOT: = comdat
+; CHECK-INTERESTINGNESS: @callee(
+; CHECK-FINAL: declare void @callee()
+
+$foo = comdat any
+
+define void @callee() comdat($foo) {
+  ret void
+}
+
+; CHECK-ALL: define void @caller()
+define void @caller() {
+entry:
+; CHECK-ALL: call void @callee()
+; CHECK-ALL: ret void
+  call void @callee()
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113486.385887.patch
Type: text/x-patch
Size: 2325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211109/f34f8d48/attachment.bin>


More information about the llvm-commits mailing list