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 @@ -9579,6 +9579,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()); diff --git a/llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll b/llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll --- a/llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll +++ b/llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll @@ -234,7 +234,7 @@ %x.05 = phi ppc_fp128 [ %d, %entry ], [ %sub, %for.body ] %arrayidx = getelementptr inbounds ppc_fp128, ppc_fp128* %n, i32 %i.06 %0 = load ppc_fp128, ppc_fp128* %arrayidx, align 8 - %sub = fsub ppc_fp128 %x.05, %0 + %sub = fsub fast ppc_fp128 %x.05, %0 %inc = add nsw i32 %i.06, 1 %exitcond = icmp eq i32 %inc, 2048 br i1 %exitcond, label %for.end, label %for.body