[llvm] [LangRef] Update the semantic of `experimental.get.vector.length` (PR #104475)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 17:18:27 PDT 2024
================
@@ -19644,13 +19644,18 @@ in order to get the number of elements to process on each loop iteration. The
result should be used to decrease the count for the next iteration until the
count reaches zero.
-If the count is larger than the number of lanes in the type described by the
-last 2 arguments, this intrinsic may return a value less than the number of
-lanes implied by the type. The result will be at least as large as the result
-will be on any later loop iteration.
-
-This intrinsic will only return 0 if the input count is also 0. A non-zero input
-count will produce a non-zero result.
+Let ``%max_lanes`` be the number of lanes in the type described by ``%vf`` and
+``%scalable``, here are the constraints on the returned value:
+- If ``%cnt`` equals to 0, returns 0.
+- The returned value is always less or equal to ``%max_lanes``.
+- The returned value is always larger or equal to ``ceil(%cnt / ceil(%cnt / %max_lanes))``.
+ - This implies that if ``%cnt`` is non-zero, the result should be non-zero
+ as well.
+ - This also implies that if ``%cnt`` is less than ``%max_lanes``, it has to
----------------
topperc wrote:
The VP vectorizer is currently generating 2 scalar induction variables. One goes through the get.vector.length and is used to set the evl for the VP intrinsics and is used by GEP indices.
The other increments by vscale * VF every loop and is used by the loop terminator. This is supposed to make the loop trip countable by SCEV.
We need to guarantee the get.vector.length based induction variable finishes the last elements on the same iteration that the `vscale * VF` based termination is reached. If get.vector.length returns fewer elements that what is necessary to have this guarantee, then some elements won't be processed before the loop ends.
The plan is to add a pass to remove the `vscale * VF` induction variable in codegen and rewrite the terminator to use the get.vector.length based induction variable.
https://github.com/llvm/llvm-project/pull/104475
More information about the llvm-commits
mailing list