[llvm] 1731bb7 - llvm-reduce: Fix not checking shouldKeep in special-globals reduction (#111647)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 08:13:10 PDT 2024


Author: Matt Arsenault
Date: 2024-10-09T19:13:06+04:00
New Revision: 1731bb79a97537c71f916f1e70a442a6615599d0

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

LOG: llvm-reduce: Fix not checking shouldKeep in special-globals reduction (#111647)

Added: 
    llvm/test/tools/llvm-reduce/special-globals-missing-should-keep-assert.ll

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/special-globals-missing-should-keep-assert.ll b/llvm/test/tools/llvm-reduce/special-globals-missing-should-keep-assert.ll
new file mode 100644
index 00000000000000..e13cd298da4b16
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/special-globals-missing-should-keep-assert.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=special-globals --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t.0
+; RUN: FileCheck --implicit-check-not=define --check-prefix=CHECK-FINAL %s < %t.0
+
+; Check that we don't hit "input module no longer interesting after
+; counting chunks" The special-globals reduction was not checking
+; shouldKeep before unconditionally erasing it.
+
+; CHECK-INTERESTINGNESS: llvm.used
+; CHECK-FINAL: llvm.used
+; CHECK-FINAL: define void @kept_used
+; CHECK-FINAL: define void @other
+ at llvm.used = appending global [2 x ptr] [ptr @kept_used, ptr @other ]
+
+define void @kept_used() {
+  ret void
+}
+
+define void @other() {
+  ret void
+}

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp
index 5b124a4052960b..aadd038033d5c0 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp
@@ -33,8 +33,10 @@ static void extractSpecialGlobalsFromModule(Oracle &O,
 
   for (StringRef Name : SpecialGlobalNames) {
     if (auto *Used = Program.getNamedGlobal(Name)) {
-      Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
-      Used->eraseFromParent();
+      if (!O.shouldKeep()) {
+        Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
+        Used->eraseFromParent();
+      }
     }
   }
 }


        


More information about the llvm-commits mailing list