[llvm-branch-commits] [llvm] 1b09e84 - Revert "[llvm][GlobalOpt] Preserve COMDATs for Dead GVs (#222720)"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 20 21:33:43 PDT 2026
Author: Kewen Meng
Date: 2026-10-20T21:33:39-07:00
New Revision: 1b09e84d13a4132b3cfb081aa20add9881243967
URL: https://github.com/llvm/llvm-project/commit/1b09e84d13a4132b3cfb081aa20add9881243967
DIFF: https://github.com/llvm/llvm-project/commit/1b09e84d13a4132b3cfb081aa20add9881243967.diff
LOG: Revert "[llvm][GlobalOpt] Preserve COMDATs for Dead GVs (#222720)"
This reverts commit fde5c72be4db40cc567d0eedf2bc0646dca4050a.
Added:
Modified:
llvm/include/llvm/IR/GlobalValue.h
llvm/lib/IR/Globals.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
Removed:
llvm/test/Transforms/GlobalOpt/deadfunction-comdat.ll
llvm/test/Transforms/GlobalOpt/deadglobal-comdat.ll
################################################################################
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 8ab220cc322da3..79e45ef51367c1 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -251,14 +251,6 @@ class GlobalValue : public Constant {
static_cast<const GlobalValue *>(this)->getComdat());
}
- /// Returns true if the \c GlobalValue is the leader of its \c Comdat group.
- /// A \c GlobalValue is considered a \c Comdat leader if it has a \c Comdat
- /// and its name matches the name of the \c Comdat group in the symbol table.
- /// For a \c GlobalAlias, this resolves through the alias to inspect the
- /// aliasee's \c Comdat, treating the alias as the leader if its own name
- /// matches the \c Comdat group name.
- LLVM_ABI bool isComdatLeader() const;
-
VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); }
bool hasDefaultVisibility() const { return Visibility == DefaultVisibility; }
bool hasHiddenVisibility() const { return Visibility == HiddenVisibility; }
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index c8ccff9f90080a..3428f662e9120f 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -284,12 +284,6 @@ const Comdat *GlobalValue::getComdat() const {
return cast<GlobalObject>(this)->getComdat();
}
-bool GlobalValue::isComdatLeader() const {
- if (hasComdat())
- return getParent()->getComdatSymbolTable().contains(getName());
- return false;
-}
-
void GlobalObject::setComdat(Comdat *C) {
if (ObjComdat)
ObjComdat->removeUser(this);
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 5941d5f3a51e30..f65f488b9bbb66 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1323,27 +1323,9 @@ deleteIfDead(GlobalValue &GV,
if (!GV.isDiscardableIfUnused() && !GV.isDeclaration())
return false;
- if (auto *C = GV.getComdat()) {
- auto IsComdatLeaderWithUses = false;
- if (GV.isComdatLeader()) {
- if (C->getUsers().size() > 1) {
- IsComdatLeaderWithUses = true;
- } else if (auto *GA = dyn_cast<GlobalAlias>(&GV)) {
- if (auto *GO = dyn_cast<GlobalObject>(GA->getAliasee())) {
- GO->removeDeadConstantUsers();
- // The alias leader has uses if the aliasee cannot be discarded, or if
- // the aliasee has uses other than this alias.
- IsComdatLeaderWithUses = !GO->hasOneUse();
- } else {
- IsComdatLeaderWithUses = true;
- }
- }
- }
-
- if (IsComdatLeaderWithUses ||
- (!GV.hasInternalLinkage() && NotDiscardableComdats.count(C)))
+ if (const Comdat *C = GV.getComdat())
+ if (!GV.hasLocalLinkage() && NotDiscardableComdats.count(C))
return false;
- }
bool Dead;
if (auto *F = dyn_cast<Function>(&GV))
diff --git a/llvm/test/Transforms/GlobalOpt/deadfunction-comdat.ll b/llvm/test/Transforms/GlobalOpt/deadfunction-comdat.ll
deleted file mode 100644
index 02b483f2aa8b64..00000000000000
--- a/llvm/test/Transforms/GlobalOpt/deadfunction-comdat.ll
+++ /dev/null
@@ -1,52 +0,0 @@
-; RUN: opt < %s -passes=globalopt -S | FileCheck %s
-
-target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-$foo = comdat any
-$trulydead = comdat any
-$aliasleader = comdat any
-
-; CHECK: @aliasleader
- at aliasleader = internal alias void (), ptr @aliasee
-
-; CHECK: @foo
-define internal void @foo() comdat {
- ret void
-}
-
-; CHECK: @bar
-define internal void @bar() #0 comdat($foo) {
- ret void
-}
-
-define void @zed() {
- call void @bar()
- ret void
-}
-
-; CHECK-NOT: @trulydead
-define internal void @trulydead() comdat {
- ret void
-}
-
-; CHECK-NOT: @trulydead2
-define internal void @trulydead2() comdat($trulydead) {
- ret void
-}
-
-; CHECK: define internal void @aliasee
-define internal void @aliasee() comdat($aliasleader) {
- ret void
-}
-
-define void @call_aliasee() {
- call void @aliasee()
- ret void
-}
-
-define i32 @main() {
- ret i32 0
-}
-
-attributes #0 = { noinline }
\ No newline at end of file
diff --git a/llvm/test/Transforms/GlobalOpt/deadglobal-comdat.ll b/llvm/test/Transforms/GlobalOpt/deadglobal-comdat.ll
deleted file mode 100644
index e1f99975a057e8..00000000000000
--- a/llvm/test/Transforms/GlobalOpt/deadglobal-comdat.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: opt < %s -passes=globalopt -S | FileCheck %s
-
-target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-; CHECK: $x
-$x = comdat any
-
-; CHECK-NOT: $trulydeadg
-$trulydeadg = comdat any
-
-; CHECK: @g
- at g = internal global i32 0, comdat($x)
-; CHECK: @g2
- at g2 = global i32 0, comdat($x)
-; CHECK: @x
- at x = internal alias i32, ptr @g
-
-; CHECK-NOT: @trulydeadg
- at trulydeadg = internal alias i32, ptr @deadg
-; CHECK-NOT: @deadg
- at deadg = internal global i32 0, comdat($trulydeadg)
\ No newline at end of file
More information about the llvm-branch-commits
mailing list