[llvm] r346204 - [LICM] Remove too conservative IsMustExecute variable
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 5 20:17:40 PST 2018
Author: mkazantsev
Date: Mon Nov 5 20:17:40 2018
New Revision: 346204
URL: http://llvm.org/viewvc/llvm-project?rev=346204&view=rev
Log:
[LICM] Remove too conservative IsMustExecute variable
LICM relies on variable `MustExecute` which is conservatively set to `false`
in all non-headers. It is used when we decide whether or not we want to hoist
an instruction or a guard.
For the guards, it might be too conservative to use this variable, we can
instead use a more precise logic from LoopSafetyInfo. Currently it is only NFC
because `IsMemoryNotModified` is also conservatively set to `false` for all
non-headers, and we cannot hoist guards from non-header blocks. However once we
give up using `IsMemoryNotModified` and use a smarter check instead, this will
allow us to hoist guards from all mustexecute non-header blocks.
Differential Revision: https://reviews.llvm.org/D50888
Reveiwed By: fedor.sergeev
Modified:
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=346204&r1=346203&r2=346204&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Mon Nov 5 20:17:40 2018
@@ -460,14 +460,10 @@ bool llvm::hoistRegion(DomTreeNode *N, A
if (inSubLoop(BB, CurLoop, LI))
continue;
- // Keep track of whether the prefix of instructions visited so far are such
- // that the next instruction visited is guaranteed to execute if the loop
- // is entered.
- bool IsMustExecute = CurLoop->getHeader() == BB;
// Keep track of whether the prefix instructions could have written memory.
- // TODO: This and IsMustExecute may be done smarter if we keep track of all
- // throwing and mem-writing operations in every block, e.g. using something
- // similar to isGuaranteedToExecute.
+ // TODO: This may be done smarter if we keep track of all throwing and
+ // mem-writing operations in every block, e.g. using something similar to
+ // isGuaranteedToExecute.
bool IsMemoryNotModified = CurLoop->getHeader() == BB;
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) {
@@ -493,10 +489,9 @@ bool llvm::hoistRegion(DomTreeNode *N, A
//
if (CurLoop->hasLoopInvariantOperands(&I) &&
canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, true, ORE) &&
- (IsMustExecute ||
- isSafeToExecuteUnconditionally(
- I, DT, CurLoop, SafetyInfo, ORE,
- CurLoop->getLoopPreheader()->getTerminator()))) {
+ isSafeToExecuteUnconditionally(
+ I, DT, CurLoop, SafetyInfo, ORE,
+ CurLoop->getLoopPreheader()->getTerminator())) {
hoist(I, DT, CurLoop, SafetyInfo, ORE);
Changed = true;
continue;
@@ -531,15 +526,13 @@ bool llvm::hoistRegion(DomTreeNode *N, A
if (((I.use_empty() &&
match(&I, m_Intrinsic<Intrinsic::invariant_start>())) ||
isGuard(&I)) &&
- IsMustExecute && IsMemoryNotModified &&
- CurLoop->hasLoopInvariantOperands(&I)) {
+ IsMemoryNotModified && CurLoop->hasLoopInvariantOperands(&I) &&
+ SafetyInfo->isGuaranteedToExecute(I, DT, CurLoop)) {
hoist(I, DT, CurLoop, SafetyInfo, ORE);
Changed = true;
continue;
}
- if (IsMustExecute)
- IsMustExecute = isGuaranteedToTransferExecutionToSuccessor(&I);
if (IsMemoryNotModified)
IsMemoryNotModified = !I.mayWriteToMemory();
}
More information about the llvm-commits
mailing list