[llvm] [LV] Ignore some costs when loop gets fully unrolled (PR #106699)
Igor Kirillov via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 6 05:32:21 PST 2024
================
@@ -2652,6 +2652,25 @@ static Value *getExpandedStep(const InductionDescriptor &ID,
return I->second;
}
+/// Knowing that loop \p L executes a single vector iteration, add instructions
+/// that will get simplified and thus should not have any cost to \p
+/// InstsToIgnore.
+static void addFullyUnrolledInstructionsToIgnore(
+ Loop *L, const LoopVectorizationLegality::InductionList &IL,
+ SmallPtrSetImpl<Instruction *> &InstsToIgnore) {
+ auto *Cmp = L->getLatchCmpInst();
+ if (Cmp)
----------------
igogo-x86 wrote:
No, it doesn't check the number of users but checks that there's only one latch in the loop. The latch is something that makes a loop to be a loop. If there is a single latch and we don't jump to the loop header, then we are exiting the loop, and the value of the condition is constant.
See, it simplifies this condition outside away (pre LV):
https://godbolt.org/z/s9q1558zY
And if the compiler couldn't do it, we should've better taught him to do it rather than adding unnecessary checks
https://github.com/llvm/llvm-project/pull/106699
More information about the llvm-commits
mailing list