Skip to content

Commit 1a25d0b

Browse files
committed
[LICM] Remove profile driven restriction on hoisting
This reverts change 2c391a5/D87551. As noted in the llvm-dev thread "LICM as canonical form" sent earlier today, introducing this was a major design change made without sufficient cause. A profile driven LICM is not an unreasonable design, it simply is not what we have. Switching to such a model requires a lot more work than just this patch, and broad aggeement that is the right direction for the optimizer as a whole. Worth noting is that all the tests included in the reverted changed are probably handled if we allow running unconstrained LICM, and later run LoopSink. As such, we have no public examples which motivate a profit based hoisting approach.
1 parent 6db2007 commit 1a25d0b

File tree

3 files changed

+0
-201
lines changed

3 files changed

+0
-201
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ static cl::opt<bool> ControlFlowHoisting(
107107
"licm-control-flow-hoisting", cl::Hidden, cl::init(false),
108108
cl::desc("Enable control flow (and PHI) hoisting in LICM"));
109109

110-
static cl::opt<unsigned> HoistSinkColdnessThreshold(
111-
"licm-coldness-threshold", cl::Hidden, cl::init(4),
112-
cl::desc("Relative coldness Threshold of hoisting/sinking destination "
113-
"block for LICM to be considered beneficial"));
114-
115110
static cl::opt<uint32_t> MaxNumUsesTraversed(
116111
"licm-max-num-uses-traversed", cl::Hidden, cl::init(8),
117112
cl::desc("Max num uses visited for identifying load "
@@ -819,35 +814,6 @@ class ControlFlowHoister {
819814
};
820815
} // namespace
821816

822-
// Hoisting/sinking instruction out of a loop isn't always beneficial. It's only
823-
// only worthwhile if the destination block is actually colder than current
824-
// block.
825-
static bool worthSinkOrHoistInst(Instruction &I, BasicBlock *DstBlock,
826-
OptimizationRemarkEmitter *ORE,
827-
BlockFrequencyInfo *BFI) {
828-
// Check block frequency only when runtime profile is available
829-
// to avoid pathological cases. With static profile, lean towards
830-
// hosting because it helps canonicalize the loop for vectorizer.
831-
if (!DstBlock->getParent()->hasProfileData())
832-
return true;
833-
834-
if (!HoistSinkColdnessThreshold || !BFI)
835-
return true;
836-
837-
BasicBlock *SrcBlock = I.getParent();
838-
if (BFI->getBlockFreq(DstBlock).getFrequency() / HoistSinkColdnessThreshold >
839-
BFI->getBlockFreq(SrcBlock).getFrequency()) {
840-
ORE->emit([&]() {
841-
return OptimizationRemarkMissed(DEBUG_TYPE, "SinkHoistInst", &I)
842-
<< "failed to sink or hoist instruction because containing block "
843-
"has lower frequency than destination block";
844-
});
845-
return false;
846-
}
847-
848-
return true;
849-
}
850-
851817
/// Walk the specified region of the CFG (defined by all blocks dominated by
852818
/// the specified block, and that are in the current loop) in depth first
853819
/// order w.r.t the DominatorTree. This allows us to visit definitions before
@@ -909,7 +875,6 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
909875
if (CurLoop->hasLoopInvariantOperands(&I) &&
910876
canSinkOrHoistInst(I, AA, DT, CurLoop, /*CurAST*/ nullptr, MSSAU,
911877
true, &Flags, ORE) &&
912-
worthSinkOrHoistInst(I, CurLoop->getLoopPreheader(), ORE, BFI) &&
913878
isSafeToExecuteUnconditionally(
914879
I, DT, TLI, CurLoop, SafetyInfo, ORE,
915880
CurLoop->getLoopPreheader()->getTerminator())) {
@@ -1741,7 +1706,6 @@ static bool sink(Instruction &I, LoopInfo *LI, DominatorTree *DT,
17411706
// First check if I is worth sinking for all uses. Sink only when it is worth
17421707
// across all uses.
17431708
SmallSetVector<User*, 8> Users(I.user_begin(), I.user_end());
1744-
SmallVector<PHINode *, 8> ExitPNs;
17451709
for (auto *UI : Users) {
17461710
auto *User = cast<Instruction>(UI);
17471711

@@ -1751,14 +1715,6 @@ static bool sink(Instruction &I, LoopInfo *LI, DominatorTree *DT,
17511715
PHINode *PN = cast<PHINode>(User);
17521716
assert(ExitBlockSet.count(PN->getParent()) &&
17531717
"The LCSSA PHI is not in an exit block!");
1754-
if (!worthSinkOrHoistInst(I, PN->getParent(), ORE, BFI)) {
1755-
return Changed;
1756-
}
1757-
1758-
ExitPNs.push_back(PN);
1759-
}
1760-
1761-
for (auto *PN : ExitPNs) {
17621718

17631719
// The PHI must be trivially replaceable.
17641720
Instruction *New = sinkThroughTriviallyReplaceablePHI(

llvm/test/Transforms/LICM/no-hoist-prof.ll

Lines changed: 0 additions & 88 deletions
This file was deleted.

llvm/test/Transforms/LICM/sink.ll

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)