[llvm] d43b4ed - llvm-reduce: Do not remove appending linkage from intrinsic globals (#131713)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 18 09:51:41 PDT 2025


Author: Matt Arsenault
Date: 2025-03-18T23:51:36+07:00
New Revision: d43b4ede6649e4ecf650a4660f62840e95043898

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

LOG: llvm-reduce: Do not remove appending linkage from intrinsic globals (#131713)

Added: 
    llvm/test/tools/llvm-reduce/reduce-linkage-intrinsic-global-variables.ll

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/reduce-linkage-intrinsic-global-variables.ll b/llvm/test/tools/llvm-reduce/reduce-linkage-intrinsic-global-variables.ll
new file mode 100644
index 0000000000000..1f3faa3b14143
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-linkage-intrinsic-global-variables.ll
@@ -0,0 +1,39 @@
+; Test that invalid reductions are not introduced by stripping the
+; required appending linkage from intrinsic global variables.
+;
+; 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: @llvm.global_ctors
+; CHECK-INTERESTINGNESS: @llvm.global_dtors
+; CHECK-INTERESTINGNESS: @llvm.used
+
+; CHECK-INTERESTINGNESS: define
+; CHECK-INTERESTINGNESS-SAME: void @f
+
+; CHECK-FINAL: define void @f()
+
+
+ at llvm.global_ctors = appending global [2 x { i32, ptr, ptr  }] [{ i32, ptr, ptr  } { i32 1, ptr @f, ptr null  }, { i32, ptr, ptr  } { i32 1, ptr @g, ptr null  }]
+ at llvm.global_dtors = appending global [2 x { i32, ptr, ptr  }] [{ i32, ptr, ptr  } { i32 1, ptr @f, ptr null  }, { i32, ptr, ptr  } { i32 1, ptr @g, ptr null  }]
+ at llvm.used = appending global [1 x ptr] [ptr @h], section "llvm.metadata"
+
+define void @f() {
+  ret void
+}
+
+; CHECK-INTERESTINGNESS: define
+; CHECK-INTERESTINGNESS-SAME: void @g
+
+; CHECK-FINAL: define void @g()
+
+define internal void @g() {
+  ret void
+}
+
+; CHECK-INTERESTINGNESS: define
+; CHECK-INTERESTINGNESS-SAME: void @h
+
+define internal void @h() {
+  ret void
+}

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
index 224fe9c412e1a..6e8c21008502f 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
@@ -38,7 +38,7 @@ static bool shouldReduceThreadLocal(GlobalValue &GV) {
 }
 
 static bool shouldReduceLinkage(GlobalValue &GV) {
-  return !GV.hasExternalLinkage();
+  return !GV.hasExternalLinkage() && !GV.hasAppendingLinkage();
 }
 
 static void reduceGVs(Oracle &O, ReducerWorkItem &Program) {


        


More information about the llvm-commits mailing list