diff --git a/llvm/test/tools/llvm-reduce/remove-bbs-comdat.ll b/llvm/test/tools/llvm-reduce/remove-bbs-comdat.ll new file mode 100644 --- /dev/null +++ b/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 +} diff --git a/llvm/test/tools/llvm-reduce/remove-bbs-entry.ll b/llvm/test/tools/llvm-reduce/remove-bbs-entry.ll new file mode 100644 --- /dev/null +++ b/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 +} diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/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(); + } } }