[llvm] a240358 - [llvm-reduce] Don't delete arguments of intrinsics

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 12:44:07 PDT 2021


Author: Langston Barrett
Date: 2021-06-21T12:43:58-07:00
New Revision: a24035883356de2bf201835e72a15f6a22e5032d

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

LOG: [llvm-reduce] Don't delete arguments of intrinsics

The argument reduction pass shouldn't remove arguments of
intrinsics, because the resulting module is ill-formed, and so
inherently uninteresting.

Reviewed By: aeubanks

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

Added: 
    llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll

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

Removed: 
    


################################################################################
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
index 0000000000000..df4e62893ac48
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
@@ -0,0 +1,14 @@
+; 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 --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s --output %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
+
+; CHECK-INTERESTINGNESS: declare void @llvm.dbg.addr
+; CHECK-FINAL: declare void @llvm.dbg.addr(metadata, metadata, metadata)
+declare void @llvm.dbg.addr(metadata, metadata, metadata)
+; CHECK-INTERESTINGNESS: declare void @llvm.dbg.declare
+; CHECK-FINAL: declare void @llvm.dbg.declare(metadata, metadata, metadata)
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+; CHECK-INTERESTINGNESS: declare void @llvm.dbg.value
+; CHECK-FINAL: 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
index c3c7dee83db10..a88bba4c4ca2a 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -7,13 +7,14 @@
 //===----------------------------------------------------------------------===//
 //
 // This file implements a function which calls the Generic Delta pass in order
-// to reduce uninteresting Arguments from defined functions.
+// to reduce uninteresting Arguments from declared and defined functions.
 //
 //===----------------------------------------------------------------------===//
 
 #include "ReduceArguments.h"
 #include "Delta.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Intrinsics.h"
 #include <set>
 #include <vector>
 
@@ -38,6 +39,14 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
     }
 }
 
+/// 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.isIntrinsic();
+}
+
 /// 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<Chunk> ChunksToKeep,
@@ -48,7 +57,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
   std::vector<Function *> 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())
@@ -100,15 +109,15 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
   }
 }
 
-/// Counts the amount of arguments in non-declaration functions and prints their
-/// respective name, index, and parent function name
+/// Counts the amount of arguments in functions and prints their respective
+/// name, index, and parent function name
 static int countArguments(Module *Program) {
   // TODO: Silence index with --quiet flag
   outs() << "----------------------------\n";
   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";


        


More information about the llvm-commits mailing list