diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/DiagnosticInfo.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 43 |
2 files changed, 38 insertions, 14 deletions
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index 07c6714e913..3acef9048cc 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -205,6 +205,15 @@ void llvm::emitOptimizationRemarkAnalysisFPCommute(LLVMContext &Ctx, DLoc, Msg)); } +void llvm::emitOptimizationRemarkAnalysisAliasing(LLVMContext &Ctx, + const char *PassName, + const Function &Fn, + const DebugLoc &DLoc, + const Twine &Msg) { + Ctx.diagnose(DiagnosticInfoOptimizationRemarkAnalysisAliasing(PassName, Fn, + DLoc, Msg)); +} + bool DiagnosticInfoOptimizationFailure::isEnabled() const { // Only print warnings. return getSeverity() == DS_Warning; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 9cfd5feca2d..37d6add20a2 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1435,7 +1435,8 @@ static void emitMissedWarning(Function *F, Loop *L, /// followed by a non-expert user. class LoopVectorizationRequirements { public: - LoopVectorizationRequirements() : UnsafeAlgebraInst(nullptr) {} + LoopVectorizationRequirements() + : NumRuntimePointerChecks(0), UnsafeAlgebraInst(nullptr) {} void addUnsafeAlgebraInst(Instruction *I) { // First unsafe algebra instruction. @@ -1443,7 +1444,11 @@ public: UnsafeAlgebraInst = I; } - bool doesNotMeet(Function *F, const LoopVectorizeHints &Hints) { + void addRuntimePointerChecks(unsigned Num) { NumRuntimePointerChecks = Num; } + + bool doesNotMeet(Function *F, Loop *L, const LoopVectorizeHints &Hints) { + bool failed = false; + if (UnsafeAlgebraInst && Hints.getForce() == LoopVectorizeHints::FK_Undefined && Hints.getWidth() == 0) { @@ -1453,12 +1458,29 @@ public: "order of operations, however IEEE 754 " "floating-point operations are not " "commutative"); - return true; + failed = true; } - return false; + + if (NumRuntimePointerChecks > + VectorizerParams::RuntimeMemoryCheckThreshold) { + emitOptimizationRemarkAnalysisAliasing( + F->getContext(), DEBUG_TYPE, *F, L->getStartLoc(), + VectorizationReport() + << "cannot prove pointers refer to independent arrays in memory. " + "The loop requires " + << NumRuntimePointerChecks + << " runtime independence checks to vectorize the loop, but that " + "would exceed the limit of " + << VectorizerParams::RuntimeMemoryCheckThreshold << " checks"); + DEBUG(dbgs() << "LV: Too many memory checks needed.\n"); + failed = true; + } + + return failed; } private: + unsigned NumRuntimePointerChecks; Instruction *UnsafeAlgebraInst; }; @@ -1714,7 +1736,7 @@ struct LoopVectorize : public FunctionPass { std::string VecDiagMsg, IntDiagMsg; bool VectorizeLoop = true, InterleaveLoop = true; - if (Requirements.doesNotMeet(F, Hints)) { + if (Requirements.doesNotMeet(F, L, Hints)) { DEBUG(dbgs() << "LV: Not vectorizing: loop did not meet vectorization " "requirements.\n"); emitMissedWarning(F, L, Hints); @@ -4297,15 +4319,8 @@ bool LoopVectorizationLegality::canVectorizeMemory() { return false; } - if (LAI->getNumRuntimePointerChecks() > - VectorizerParams::RuntimeMemoryCheckThreshold) { - emitAnalysis(VectorizationReport() - << LAI->getNumRuntimePointerChecks() << " exceeds limit of " - << VectorizerParams::RuntimeMemoryCheckThreshold - << " dependent memory operations checked at runtime"); - DEBUG(dbgs() << "LV: Too many memory checks needed.\n"); - return false; - } + Requirements->addRuntimePointerChecks(LAI->getNumRuntimePointerChecks()); + return true; } |