[llvm] d2640f5 - [StructuralHash] Ignore global variable declarations
Mikael Holmen via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 22:53:25 PDT 2023
Author: Mikael Holmen
Date: 2023-06-29T07:51:49+02:00
New Revision: d2640f596c4763596ab92dadbdd0477afae4190f
URL: https://github.com/llvm/llvm-project/commit/d2640f596c4763596ab92dadbdd0477afae4190f
DIFF: https://github.com/llvm/llvm-project/commit/d2640f596c4763596ab92dadbdd0477afae4190f.diff
LOG: [StructuralHash] Ignore global variable declarations
Ignore declarations of global variables, just as we do with declarations
of functions.
Done as a follow up to the comments in https://reviews.llvm.org/D149209
Differential Revision: https://reviews.llvm.org/D153855
# Conflicts:
# llvm/lib/IR/StructuralHash.cpp
Added:
llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
Modified:
llvm/lib/IR/StructuralHash.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp
index 25a43810ad027b..ca58cf9e718a48 100644
--- a/llvm/lib/IR/StructuralHash.cpp
+++ b/llvm/lib/IR/StructuralHash.cpp
@@ -58,9 +58,10 @@ class StructuralHashImpl {
}
void update(const GlobalVariable &GV) {
- // used/compiler.used don't affect analyses.
+ // Declarations and used/compiler.used don't affect analyses.
// Same for llvm.embedded.object, which is always a metadata section.
- if (GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used" ||
+ if (GV.isDeclaration() ||
+ GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used" ||
GV.getName() == "llvm.embedded.object")
return;
hash(23456); // Global header
diff --git a/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll b/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
new file mode 100644
index 00000000000000..c6ffd23cc23d2d
--- /dev/null
+++ b/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
@@ -0,0 +1,9 @@
+; RUN: opt -passes=strip-dead-prototypes -S -verify-analysis-invalidation < %s | FileCheck %s
+
+; The declaration of the unused global variable @.str should be removed without
+; getting any error from -verify-analysis-invalidation.
+
+; CHECK-NOT: @.str
+
+ at .str = external constant [15 x i16]
+
More information about the llvm-commits
mailing list