[PATCH] [LoopAccesses] Add canAnalyzeLoop
Adam Nemet
anemet at apple.com
Mon Feb 16 14:20:20 PST 2015
Hi hfinkel, aschwaighofer, nadav,
This allows the analysis to be attempted with any loop. This feature
will be used with -analysis. (LV only requests the analysis on loops
that have already satisfied these tests.)
This is part of the patchset that converts LoopAccessAnalysis into an
actual analysis pass.
http://reviews.llvm.org/D7688
Files:
include/llvm/Analysis/LoopAccessAnalysis.h
lib/Analysis/LoopAccessAnalysis.cpp
Index: include/llvm/Analysis/LoopAccessAnalysis.h
===================================================================
--- include/llvm/Analysis/LoopAccessAnalysis.h
+++ include/llvm/Analysis/LoopAccessAnalysis.h
@@ -131,6 +131,10 @@
/// no memory dependence cycles.
bool canVectorizeMemory() { return CanVecMem; }
+ /// \brief Check if the structure of the loop allows it to be analyzed by this
+ /// pass.
+ bool canAnalyzeLoop();
+
RuntimePointerCheck *getRuntimePointerCheck() { return &PtrRtCheck; }
/// Return true if the block BB needs to be predicated in order for the loop
Index: lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- lib/Analysis/LoopAccessAnalysis.cpp
+++ lib/Analysis/LoopAccessAnalysis.cpp
@@ -829,6 +829,55 @@
return true;
}
+bool LoopAccessInfo::canAnalyzeLoop() {
+ // We can only vectorize innermost loops.
+ if (!TheLoop->empty()) {
+ emitAnalysis(VectorizationReport() << "loop is not the innermost loop");
+ return false;
+ }
+
+ // We must have a single backedge.
+ if (TheLoop->getNumBackEdges() != 1) {
+ emitAnalysis(
+ VectorizationReport() <<
+ "loop control flow is not understood by vectorizer");
+ return false;
+ }
+
+ // We must have a single exiting block.
+ if (!TheLoop->getExitingBlock()) {
+ emitAnalysis(
+ VectorizationReport() <<
+ "loop control flow is not understood by vectorizer");
+ return false;
+ }
+
+ // We only handle bottom-tested loops, i.e. loop in which the condition is
+ // checked at the end of each iteration. With that we can assume that all
+ // instructions in the loop are executed the same number of times.
+ if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {
+ emitAnalysis(
+ VectorizationReport() <<
+ "loop control flow is not understood by vectorizer");
+ return false;
+ }
+
+ // We need to have a loop header.
+ DEBUG(dbgs() << "LAA: Found a loop: " <<
+ TheLoop->getHeader()->getName() << '\n');
+
+ // ScalarEvolution needs to be able to find the exit count.
+ const SCEV *ExitCount = SE->getBackedgeTakenCount(TheLoop);
+ if (ExitCount == SE->getCouldNotCompute()) {
+ emitAnalysis(VectorizationReport() <<
+ "could not determine number of loop iterations");
+ DEBUG(dbgs() << "LAA: SCEV could not compute the loop exit count.\n");
+ return false;
+ }
+
+ return true;
+}
+
void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
typedef SmallVector<Value*, 16> ValueVector;
@@ -1220,7 +1269,8 @@
if (!LAI) {
LAI = make_unique<LoopAccessInfo>(L, SE, DL, TLI, AA, DT);
- LAI->analyzeLoop(Strides);
+ if (LAI->canAnalyzeLoop())
+ LAI->analyzeLoop(Strides);
#ifndef NDEBUG
LAI->NumSymbolicStrides = Strides.size();
#endif
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7688.20057.patch
Type: text/x-patch
Size: 2855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150216/cd83006c/attachment.bin>
More information about the llvm-commits
mailing list