diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h --- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h +++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h @@ -189,6 +189,11 @@ bool doesNotMeet(Function *F, Loop *L, const LoopVectorizeHints &Hints); + Instruction *getExactFPInst() { return ExactFPMathInst; } + bool canVectorizeFPMath(const LoopVectorizeHints &Hints) const { + return !ExactFPMathInst || Hints.allowReordering(); + } + private: unsigned NumRuntimePointerChecks = 0; Instruction *ExactFPMathInst = nullptr; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp @@ -250,16 +250,6 @@ Function *F, Loop *L, const LoopVectorizeHints &Hints) { const char *PassName = Hints.vectorizeAnalysisPassName(); bool Failed = false; - if (ExactFPMathInst && !Hints.allowReordering()) { - ORE.emit([&]() { - return OptimizationRemarkAnalysisFPCommute( - PassName, "CantReorderFPOps", ExactFPMathInst->getDebugLoc(), - ExactFPMathInst->getParent()) - << "loop not vectorized: cannot prove it is safe to reorder " - "floating-point operations"; - }); - Failed = true; - } // Test if runtime memcheck thresholds are exceeded. bool PragmaThresholdReached = diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -9599,6 +9599,21 @@ return false; } + if (!Requirements.canVectorizeFPMath(Hints)) { + ORE->emit([&]() { + auto *ExactFPMathInst = Requirements.getExactFPInst(); + return OptimizationRemarkAnalysisFPCommute(DEBUG_TYPE, "CantReorderFPOps", + ExactFPMathInst->getDebugLoc(), + ExactFPMathInst->getParent()) + << "loop not vectorized: cannot prove it is safe to reorder " + "floating-point operations"; + }); + LLVM_DEBUG(dbgs() << "LV: loop not vectorized: cannot prove it is safe to " + "reorder floating-point operations\n"); + Hints.emitRemarkWithHints(); + return false; + } + bool UseInterleaved = TTI->enableInterleavedAccessVectorization(); InterleavedAccessInfo IAI(PSE, L, DT, LI, LVL.getLAI());