[llvm] [LV] Ignore some costs when loop gets fully unrolled (PR #106699)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 05:40:04 PST 2024
================
@@ -5544,14 +5544,28 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
InstructionCost LoopVectorizationCostModel::expectedCost(ElementCount VF) {
InstructionCost Cost;
+ // If with the given VF loop gets fully unrolled, ignore the costs of
+ // comparison and induction instructions, as they'll get simplified away
+ SmallPtrSet<const Value *, 16> ValuesToIgnoreForVF;
+ auto TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
+ auto *Cmp = TheLoop->getLatchCmpInst();
+ if (Cmp && TC == VF.getKnownMinValue()) {
+ ValuesToIgnoreForVF.insert(Cmp);
+ for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
----------------
david-arm wrote:
I don't think this looks right, since there could be outside users of the induction variables and the increment will remain even after the loop is removed. I think you need to make sure that the only use of the increment is the phi in the loop header.
https://github.com/llvm/llvm-project/pull/106699
More information about the llvm-commits
mailing list