[llvm] 9071393 - [GlobalDCE] Simplify and return Changed = true less often
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 17 08:03:20 PST 2022
Author: Jay Foad
Date: 2022-02-17T16:03:13Z
New Revision: 9071393c18e5264e3bbf3ca3f3584fa5f45be6c2
URL: https://github.com/llvm/llvm-project/commit/9071393c18e5264e3bbf3ca3f3584fa5f45be6c2
DIFF: https://github.com/llvm/llvm-project/commit/9071393c18e5264e3bbf3ca3f3584fa5f45be6c2.diff
LOG: [GlobalDCE] Simplify and return Changed = true less often
Removing dead constants should not count as making a change to the
module. This means that RemoveUnusedGlobalValue simplifies to just
calling removeDeadConstantUsers, so inline it.
Differential Revision: https://reviews.llvm.org/D120052
Added:
Modified:
llvm/lib/Transforms/IPO/GlobalDCE.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index 5e5d2086adc2e..e375504099610 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -317,7 +317,7 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
// Loop over the module, adding globals which are obviously necessary.
for (GlobalObject &GO : M.global_objects()) {
- Changed |= RemoveUnusedGlobalValue(GO);
+ GO.removeDeadConstantUsers();
// Functions with external linkage are needed if they have a body.
// Externally visible & appending globals are needed, if they have an
// initializer.
@@ -330,7 +330,7 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
// Compute direct dependencies of aliases.
for (GlobalAlias &GA : M.aliases()) {
- Changed |= RemoveUnusedGlobalValue(GA);
+ GA.removeDeadConstantUsers();
// Externally visible aliases are needed.
if (!GA.isDiscardableIfUnused())
MarkLive(GA);
@@ -340,7 +340,7 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
// Compute direct dependencies of ifuncs.
for (GlobalIFunc &GIF : M.ifuncs()) {
- Changed |= RemoveUnusedGlobalValue(GIF);
+ GIF.removeDeadConstantUsers();
// Externally visible ifuncs are needed.
if (!GIF.isDiscardableIfUnused())
MarkLive(GIF);
@@ -403,7 +403,7 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
// Now that all interferences have been dropped, delete the actual objects
// themselves.
auto EraseUnusedGlobalValue = [&](GlobalValue *GV) {
- RemoveUnusedGlobalValue(*GV);
+ GV->removeDeadConstantUsers();
GV->eraseFromParent();
Changed = true;
};
@@ -455,16 +455,3 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
return PreservedAnalyses::none();
return PreservedAnalyses::all();
}
-
-// RemoveUnusedGlobalValue - Loop over all of the uses of the specified
-// GlobalValue, looking for the constant pointer ref that may be pointing to it.
-// If found, check to see if the constant pointer ref is safe to destroy, and if
-// so, nuke it. This will reduce the reference count on the global value, which
-// might make it deader.
-//
-bool GlobalDCEPass::RemoveUnusedGlobalValue(GlobalValue &GV) {
- if (GV.use_empty())
- return false;
- GV.removeDeadConstantUsers();
- return GV.use_empty();
-}
More information about the llvm-commits
mailing list