summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2018-08-21 08:11:31 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2018-08-21 08:11:31 +0000
commit097ef69182d65c6687822a2a846bf82de5cf2686 (patch)
tree17a091fb90aee9f7b46a7c30508ea8dad0f382af /llvm/lib
parent880f29157770a2fe51f08887c363e789f8d47ba6 (diff)
downloadbcm5719-llvm-097ef69182d65c6687822a2a846bf82de5cf2686.tar.gz
bcm5719-llvm-097ef69182d65c6687822a2a846bf82de5cf2686.zip
[LICM] Hoist guards with invariant conditions
This patch teaches LICM to hoist guards from the loop if they are guaranteed to execute and if there are no side effects that could prevent that. Differential Revision: https://reviews.llvm.org/D50501 Reviewed By: reames llvm-svn: 340256
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index ee187c1d601..aea09c76524 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -58,6 +58,7 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/PredIteratorCache.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
@@ -465,6 +466,11 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
// 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.
+ bool IsMemoryNotModified = CurLoop->getHeader() == BB;
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) {
Instruction &I = *II++;
@@ -523,8 +529,19 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
continue;
}
+ using namespace PatternMatch;
+ if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>()) &&
+ IsMustExecute && IsMemoryNotModified &&
+ CurLoop->hasLoopInvariantOperands(&I)) {
+ hoist(I, DT, CurLoop, SafetyInfo, ORE);
+ Changed = true;
+ continue;
+ }
+
if (IsMustExecute)
IsMustExecute = isGuaranteedToTransferExecutionToSuccessor(&I);
+ if (IsMemoryNotModified)
+ IsMemoryNotModified = !I.mayWriteToMemory();
}
}
OpenPOWER on IntegriCloud