[PATCH] D98633: [LV] Move exact FP math check out of Requirements.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 15 08:42:16 PDT 2021
fhahn created this revision.
fhahn added reviewers: Ayal, hsaito, ebrevnov, anemet, lebedev.ri.
Herald added subscribers: hiraditya, nemanjai.
fhahn requested review of this revision.
Herald added a project: LLVM.
We know if the loop contains FP instructions preventing vectorization
after we are done with legality checks. This patch updates the code the
check for un-vectorizable FP operations earlier, to avoid unnecessarily
running the cost model and picking a vectorization factor. It also makes
the code more direct and moves the check to a position where similar
checks are done.
I might be missing something, but I don't see any reason to handle this
check differently to other, similar checks.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98633
Files:
llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll
Index: llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/PowerPC/reg-usage.ll
+++ 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
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ 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());
Index: llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ 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 =
Index: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
===================================================================
--- llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98633.330677.patch
Type: text/x-patch
Size: 3386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210315/b07a8b85/attachment.bin>
More information about the llvm-commits
mailing list