[llvm] 6187eeb - [llvm-reduce] Fix incorrect indices in argument reduction pass

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 19 10:07:22 PDT 2020


Author: Alex Richardson
Date: 2020-07-19T18:06:47+01:00
New Revision: 6187eeb683d8c639282d437e6af585e9b7f9c93e

URL: https://github.com/llvm/llvm-project/commit/6187eeb683d8c639282d437e6af585e9b7f9c93e
DIFF: https://github.com/llvm/llvm-project/commit/6187eeb683d8c639282d437e6af585e9b7f9c93e.diff

LOG: [llvm-reduce] Fix incorrect indices in argument reduction pass

The function extractArgumentsFromModule() was passing a one-based index to,
but replaceFunctionCalls() was expecting a zero-based argument index. This
resulted in assertion errors when reducing function call arguments with
different types. Additionally, the

Reviewed By: lebedev.ri

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

Added: 
    llvm/test/Reduce/remove-args-2.ll

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Reduce/remove-args-2.ll b/llvm/test/Reduce/remove-args-2.ll
new file mode 100644
index 000000000000..fddcfc75195c
--- /dev/null
+++ b/llvm/test/Reduce/remove-args-2.ll
@@ -0,0 +1,20 @@
+; 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 %python --test-arg %p/Inputs/remove-args.py %s -o %t
+; RUN: cat %t | FileCheck -implicit-check-not=uninteresting %s
+
+%struct.foo = type { %struct.foo*, i32, i32, i8* }
+
+define dso_local void @bar() {
+entry:
+  ; CHECK: call void @interesting(%struct.foo* null)
+  call void @interesting(i32 0, i8* null, %struct.foo* null, i8* null, i64 0)
+  ret void
+}
+
+; CHECK: define internal void @interesting(%struct.foo* %interesting) {
+define internal void @interesting(i32 %uninteresting1, i8* %uninteresting2, %struct.foo* %interesting, i8* %uninteresting3, i64 %uninteresting4) {
+entry:
+  ret void
+}

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
index a119b40018b3..88c3e326ff97 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -81,10 +81,9 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
       continue;
 
     std::set<int> ArgIndexesToKeep;
-    int ArgI = 0;
-    for (auto &Arg : F->args())
-      if (ArgsToKeep.count(&Arg))
-        ArgIndexesToKeep.insert(++ArgI);
+    for (auto &Arg : enumerate(F->args()))
+      if (ArgsToKeep.count(&Arg.value()))
+        ArgIndexesToKeep.insert(Arg.index());
 
     auto *ClonedFunc = CloneFunction(F, VMap);
     // In order to preserve function order, we move Clone after old Function


        


More information about the llvm-commits mailing list