Author: Roman Lebedev Date: 2021-01-03T01:45:47+03:00 New Revision: 19ab1817b61d3b716f69f78f727de8bd8887f53f
URL: https://github.com/llvm/llvm-project/commit/19ab1817b61d3b716f69f78f727de8bd8887f53f DIFF: https://github.com/llvm/llvm-project/commit/19ab1817b61d3b716f69f78f727de8bd8887f53f.diff LOG: [llvm-reduce] Fix removal of unused llvm intrinsics declarations ee6e25e4391a6d3ac0a3c89615474e512f44cda6 changed the delta pass to skip intrinsics, which means we may end up being left with declarations of intrinsics, that aren't otherwise referenced in the module. This is obviously unwanted, do drop them. Added: llvm/test/Reduce/remove-unused-declarations.ll Modified: llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp Removed: ################################################################################ diff --git a/llvm/test/Reduce/remove-unused-declarations.ll b/llvm/test/Reduce/remove-unused-declarations.ll new file mode 100644 index 000000000000..5ae3a3edbad0 --- /dev/null +++ b/llvm/test/Reduce/remove-unused-declarations.ll @@ -0,0 +1,21 @@ +; RUN: llvm-reduce --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 --implicit-check-not=uninteresting %s + +declare void @llvm.uninteresting() +declare void @uninteresting() + +; CHECK-ALL: declare void @llvm.interesting() +; CHECK-ALL: declare void @interesting() +declare void @llvm.interesting() +declare void @interesting() + +; CHECK-ALL: define void @main() { +; CHECK-ALL-NEXT: call void @llvm.interesting() +; CHECK-ALL-NEXT: call void @interesting() +; CHECK-ALL-NEXT: ret void +; CHECK-ALL-NEXT: } +define void @main() { + call void @llvm.interesting() + call void @interesting() + ret void +} diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp index 6bb8f81c3dbd..d100935ee422 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp @@ -33,8 +33,8 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep, [&O](Function &F) { // Intrinsics don't have function bodies that are useful to // reduce. Additionally, intrinsics may have additional operand - // constraints. - return !F.isIntrinsic() && !O.shouldKeep(); + // constraints. But, do drop intrinsics that are not referenced. + return (!F.isIntrinsic() || F.use_empty()) && !O.shouldKeep(); }); // Then, drop body of each of them. We want to batch this and do nothing else @@ -51,7 +51,7 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep, } } -/// Counts the amount of non-declaration functions and prints their +/// Counts the amount of functions and prints their /// respective name & index static int countFunctions(Module *Program) { // TODO: Silence index with --quiet flag @@ -59,7 +59,7 @@ static int countFunctions(Module *Program) { errs() << "Function Index Reference:\n"; int FunctionCount = 0; for (auto &F : *Program) { - if (F.isIntrinsic()) + if (F.isIntrinsic() && !F.use_empty()) continue; errs() << '\t' << ++FunctionCount << ": " << F.getName() << '\n'; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits