[PATCH] D153855: [StructuralHash] Ignore global variable declarations

Mikael Holmén via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 22:26:37 PDT 2023


uabelho updated this revision to Diff 535236.
uabelho added a comment.

Simplified testcase


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153855/new/

https://reviews.llvm.org/D153855

Files:
  llvm/lib/IR/StructuralHash.cpp
  llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll


Index: llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
===================================================================
--- /dev/null
+++ 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]
+
Index: llvm/lib/IR/StructuralHash.cpp
===================================================================
--- llvm/lib/IR/StructuralHash.cpp
+++ llvm/lib/IR/StructuralHash.cpp
@@ -58,8 +58,9 @@
   }
 
   void update(const GlobalVariable &GV) {
-    // used/compiler.used don't affect analyses.
-    if (GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used")
+    // Declarations and used/compiler.used don't affect analyses.
+    if (GV.isDeclaration() || GV.getName() == "llvm.compiler.used" ||
+        GV.getName() == "llvm.used")
       return;
     hash(23456); // Global header
     hash(GV.getValueType()->getTypeID());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153855.535236.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230628/9c2303f7/attachment.bin>


More information about the llvm-commits mailing list