diff --git a/llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll b/llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll @@ -0,0 +1,23 @@ +; Test that llvm-reduce can remove uninteresting function arguments from function definitions as well as their calls. +; This test checks that functions with different argument types are handled correctly +; +; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s --input-file %t + +declare void @pass(void (i32, i8*, i64*)*) + +define void @bar() { +entry: + ; CHECK-INTERESTINGNESS: call void @pass({{.*}}@interesting + ; CHECK-FINAL: call void @pass(void (i32, i8*, i64*)* bitcast (void (i64*)* @interesting to void (i32, i8*, i64*)*)) + call void @pass(void (i32, i8*, i64*)* @interesting) + ret void +} + +; CHECK-ALL: define internal void @interesting +; CHECK-INTERESTINGNESS-SAME: ({{.*}}%interesting{{.*}}) { +; CHECK-FINAL-SAME: (i64* %interesting) +define internal void @interesting(i32 %uninteresting1, i8* %uninteresting2, i64* %interesting) { +entry: + ret void +} 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 @@ -26,6 +26,10 @@ const auto &Users = OldF.users(); for (auto I = Users.begin(), E = Users.end(); I != E; ) if (auto *CI = dyn_cast(*I++)) { + // Skip uses in call instructions where OldF isn't the called function + // (e.g. if OldF is an argument of the call). + if (CI->getCalledFunction() != &OldF) + continue; SmallVector Args; for (auto ArgI = CI->arg_begin(), E = CI->arg_end(); ArgI != E; ++ArgI) if (ArgIndexesToKeep.count(ArgI - CI->arg_begin()))