[PATCH] D109759: [llvm-reduce] Skip updating calls where OldF isn't the called fn.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 14 06:29:29 PDT 2021


fhahn created this revision.
fhahn added reviewers: arichardson, aeubanks, lebedev.ri, dblaikie.
fhahn requested review of this revision.
Herald added a project: LLVM.

When replacing function calls, skip call instructions where the old
function is not the called function, but e.g. the old function is passed
as an argument.

This fixes a crash due to trying to construct invalid IR for the test
case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109759

Files:
  llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll
  llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp


Index: llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ 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<CallInst>(*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<Value *, 8> Args;
       for (auto ArgI = CI->arg_begin(), E = CI->arg_end(); ArgI != E; ++ArgI)
         if (ArgIndexesToKeep.count(ArgI - CI->arg_begin()))
Index: llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll
===================================================================
--- /dev/null
+++ 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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109759.372470.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210914/000c3e73/attachment.bin>


More information about the llvm-commits mailing list