From b4efc0f070baefa6a308f0cf4d23cd71ad608deb Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 3 Jul 2023 22:39:40 +0100 Subject: [PATCH] [LV] Break up condition in selectEpilogueVectorizationFactor loop (NFCI) Restructure the loop as suggested in D154264 to increase readability and make it easier to extend. --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index bf0ce24..b60c538 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5699,13 +5699,21 @@ VectorizationFactor LoopVectorizationPlanner::selectEpilogueVectorizationFactor( EstimatedRuntimeVF *= *VScale; } - for (auto &NextVF : ProfitableVFs) - if (((!NextVF.Width.isScalable() && MainLoopVF.isScalable() && - ElementCount::isKnownLT(NextVF.Width, EstimatedRuntimeVF)) || - ElementCount::isKnownLT(NextVF.Width, MainLoopVF)) && - (Result.Width.isScalar() || isMoreProfitable(NextVF, Result)) && - hasPlanWithVF(NextVF.Width)) + for (auto &NextVF : ProfitableVFs) { + // Skip candidate VFs without a corresponding VPlan. + if (!hasPlanWithVF(NextVF.Width)) + continue; + + // Skip candidate VFs with widths >= the estimate runtime VF (scalable + // vectors) or the VF of the main loop (fixed vectors). + if ((!NextVF.Width.isScalable() && MainLoopVF.isScalable() && + ElementCount::isKnownGE(NextVF.Width, EstimatedRuntimeVF)) || + ElementCount::isKnownGE(NextVF.Width, MainLoopVF)) + continue; + + if (Result.Width.isScalar() || isMoreProfitable(NextVF, Result)) Result = NextVF; + } if (Result != VectorizationFactor::Disabled()) LLVM_DEBUG(dbgs() << "LEV: Vectorizing epilogue loop with VF = " -- 2.7.4