[llvm] llvm-reduce: Fix not checking shouldKeep in special-globals reduction (PR #111647)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 01:41:08 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/111647
Fixes "input module no longer interesting after counting chunks"
assertion on cases where llvm.used matters.
>From 19a7b3abeb158fa19448d58e259ea178946c9a13 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 9 Oct 2024 12:38:29 +0400
Subject: [PATCH] llvm-reduce: Fix not checking shouldKeep in special-globals
reduction
Fixes "input module no longer interesting after counting chunks"
assertion on cases where llvm.used matters.
---
...cial-globals-missing-should-keep-assert.ll | 20 +++++++++++++++++++
.../deltas/ReduceSpecialGlobals.cpp | 6 ++++--
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/tools/llvm-reduce/special-globals-missing-should-keep-assert.ll
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