[llvm] 57fbb9e - [llvm-reduce] Skip updating calls where OldF isn't the called fn.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 1 02:53:28 PDT 2021


Author: Florian Hahn
Date: 2021-10-01T10:52:48+01:00
New Revision: 57fbb9ed0e4c9717b1106ce18f5653ce8f7136fa

URL: https://github.com/llvm/llvm-project/commit/57fbb9ed0e4c9717b1106ce18f5653ce8f7136fa
DIFF: https://github.com/llvm/llvm-project/commit/57fbb9ed0e4c9717b1106ce18f5653ce8f7136fa.diff

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

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.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D109759

Added: 
    llvm/test/tools/llvm-reduce/remove-args-fn-passed-through-call.ll

Modified: 
    llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp

Removed: 
    


################################################################################
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
index 0000000000000..1773397865b72
--- /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 
diff erent 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
index a88bba4c4ca2a..f36ef4f7bfb29 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -26,6 +26,10 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
   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()))


        


More information about the llvm-commits mailing list