diff --git a/llvm/test/tools/llvm-reduce/remove-dso-local.ll b/llvm/test/tools/llvm-reduce/remove-dso-local.ll --- a/llvm/test/tools/llvm-reduce/remove-dso-local.ll +++ b/llvm/test/tools/llvm-reduce/remove-dso-local.ll @@ -1,6 +1,6 @@ ; Test that llvm-reduce can remove dso_local. ; -; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t ; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t ; CHECK-INTERESTINGNESS: declare @@ -22,3 +22,7 @@ declare dso_local void @f1(i32, i32) +; CHECK-INTERESTINGNESS: define {{.*}} @f2 +define private void @f2(i32, i32) { + ret void +} diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -15,6 +15,7 @@ #include "Delta.h" #include "llvm/ADT/STLExtras.h" #include "llvm/IR/Verifier.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Transforms/Utils/Cloning.h" #include @@ -22,6 +23,10 @@ using namespace llvm; +static cl::opt AbortOnInvalidReduction( + "abort-on-invalid-reduction", + cl::desc("Abort if any reduction results in invalid IR")); + void writeOutput(llvm::Module *M, llvm::StringRef Message); bool isReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) { @@ -141,6 +146,10 @@ // Some reductions may result in invalid IR. Skip such reductions. if (verifyModule(*Clone.get(), &errs())) { + if (AbortOnInvalidReduction) { + errs() << "Invalid reduction\n"; + exit(1); + } errs() << " **** WARNING | reduction resulted in invalid module, " "skipping\n"; continue; diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp @@ -17,6 +17,10 @@ using namespace llvm; +static bool isValidDSOLocalReductionGV(GlobalValue &GV) { + return GV.isDSOLocal() && !GV.isImplicitDSOLocal(); +} + /// Sets dso_local to false for all global values. static void extractGVsFromModule(std::vector ChunksToKeep, Module *Program) { @@ -24,7 +28,7 @@ // remove dso_local from global values for (auto &GV : Program->global_values()) - if (GV.isDSOLocal() && !O.shouldKeep()) { + if (isValidDSOLocalReductionGV(GV) && !O.shouldKeep()) { GV.setDSOLocal(false); } } @@ -37,7 +41,7 @@ outs() << "GlobalValue Index Reference:\n"; int GVCount = 0; for (auto &GV : Program->global_values()) - if (GV.isDSOLocal()) + if (isValidDSOLocalReductionGV(GV)) outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n"; outs() << "----------------------------\n"; return GVCount;