diff --git a/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll b/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll @@ -0,0 +1,9 @@ +; llvm-reduce shouldn't remove arguments of debug intrinsics, because the resulting module will be ill-formed. +; +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test=FileCheck --test-arg=%s --output=%t %s +; CHECK: declare void @llvm.dbg.addr(metadata, metadata, metadata) +declare void @llvm.dbg.addr(metadata, metadata, metadata) +; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) +declare void @llvm.dbg.declare(metadata, metadata, metadata) +; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) +declare void @llvm.dbg.value(metadata, metadata, metadata) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -14,6 +14,7 @@ #include "ReduceArguments.h" #include "Delta.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/IR/Intrinsics.h" #include #include @@ -38,6 +39,14 @@ } } +/// Returns whether or not this function should be considered a candidate for +/// argument removal. Currently, functions with no arguments and intrinsics are +/// not considered. Intrinsics aren't considered because their signatures are +/// fixed. +static bool shouldRemoveArguments(const Function &F) { + return !F.arg_empty() && F.getIntrinsicID() == Intrinsic::not_intrinsic; +} + /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. static void extractArgumentsFromModule(std::vector ChunksToKeep, @@ -48,7 +57,7 @@ std::vector Funcs; // Get inside-chunk arguments, as well as their parent function for (auto &F : *Program) - if (!F.arg_empty()) { + if (shouldRemoveArguments(F)) { Funcs.push_back(&F); for (auto &A : F.args()) if (O.shouldKeep()) @@ -108,7 +117,7 @@ outs() << "Param Index Reference:\n"; int ArgsCount = 0; for (auto &F : *Program) - if (!F.arg_empty()) { + if (shouldRemoveArguments(F)) { outs() << " " << F.getName() << "\n"; for (auto &A : F.args()) outs() << "\t" << ++ArgsCount << ": " << A.getName() << "\n";