[llvm-reduce] Fix removal of unused llvm intrinsics declarations

ee6e25e439 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.
This commit is contained in:
Roman Lebedev 2021-01-02 19:29:01 +03:00
parent 7c8b8063b6
commit 19ab1817b6
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 25 additions and 4 deletions

View File

@ -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
}

View File

@ -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';