From d76c1d2247af599a67fcfee6b1ebfcffed99ee7c Mon Sep 17 00:00:00 2001 From: Yevgeny Rouban Date: Mon, 28 Dec 2020 10:54:21 +0700 Subject: [PATCH] [RS4GC] Lazily set changed flag when folding single entry phis The function FoldSingleEntryPHINodes() is changed to return if it has changed IR or not. This return value is used by RS4GC to set the MadeChange flag respectively. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D93810 --- llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h | 2 +- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 6 ++---- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h index 7b8e2be17fa20..64c569de1f581 100644 --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -74,7 +74,7 @@ bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU = nullptr, /// in it, fold them away. This handles the case when all entries to the PHI /// nodes in a block are guaranteed equal, such as when the block has exactly /// one predecessor. -void FoldSingleEntryPHINodes(BasicBlock *BB, +bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep = nullptr); /// Examine each PHI in the given block and delete it if it is dead. Also diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index 663770298ee01..68ddebf113d18 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -2735,10 +2735,8 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT, // of liveness sets for no good reason. It may be harder to do this post // insertion since relocations and base phis can confuse things. for (BasicBlock &BB : F) - if (BB.getUniquePredecessor()) { - MadeChange = true; - FoldSingleEntryPHINodes(&BB); - } + if (BB.getUniquePredecessor()) + MadeChange |= FoldSingleEntryPHINodes(&BB); // Before we start introducing relocations, we want to tweak the IR a bit to // avoid unfortunate code generation effects. The main example is that we diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 14795d450d3d0..5b8bc184daca0 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -136,9 +136,10 @@ bool llvm::EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU, return !DeadBlocks.empty(); } -void llvm::FoldSingleEntryPHINodes(BasicBlock *BB, +bool llvm::FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep) { - if (!isa(BB->begin())) return; + if (!isa(BB->begin())) + return false; while (PHINode *PN = dyn_cast(BB->begin())) { if (PN->getIncomingValue(0) != PN) @@ -151,6 +152,7 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB, PN->eraseFromParent(); } + return true; } bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,