[llvm] 511f2ce - [llvm-reduce] Don't unset dso_local on implicitly dso_local GVs

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 11:58:14 PDT 2021


Author: Arthur Eubanks
Date: 2021-04-30T11:57:22-07:00
New Revision: 511f2cecf7c95aa2eea7447818bddf08f7222daa

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

LOG: [llvm-reduce] Don't unset dso_local on implicitly dso_local GVs

This introduces a flag that aborts if we ever reduce to IR that fails
the verifier.

Reviewed By: swamulism, arichardson

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-reduce/remove-dso-local.ll
    llvm/tools/llvm-reduce/deltas/Delta.cpp
    llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/remove-dso-local.ll b/llvm/test/tools/llvm-reduce/remove-dso-local.ll
index 6589057d125cb..dd9398bd9e434 100644
--- 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 @f0(i32, i32)
 
 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
index 75d927955e8af..10597641b4804 100644
--- 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 <fstream>
@@ -22,6 +23,10 @@
 
 using namespace llvm;
 
+static cl::opt<bool> 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 @@ void llvm::runDeltaPass(
 
       // 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
index 73aa15d6aaa72..4d918aa586a49 100644
--- 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<Chunk> ChunksToKeep,
                                  Module *Program) {
@@ -24,7 +28,7 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
 
   // 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 @@ static int countGVs(Module *Program) {
   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;


        


More information about the llvm-commits mailing list