Skip to content

Commit

Permalink
[LangRef] Update the semantic of experimental.get.vector.length (#1…
Browse files Browse the repository at this point in the history
…04475)

The previous semantics of `llvm.experimental.get.vector.length` was too
permissive such that it gave optimizers a hard time on anything related
to the number of iterations of VP-vectorized loops.

This patch tries to address this by assigning it a set of stricter
semantics similar to that of RVV's VSETVLI instructions, while being not
too RISC-V specific and leaving room for other (future) targets.

---------

Co-authored-by: Craig Topper <[email protected]>
  • Loading branch information
mshockwave and topperc authored Aug 27, 2024
1 parent d880f5a commit e806370
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19641,7 +19641,7 @@ vectorization factor should be multiplied by vscale.
Semantics:
""""""""""

Returns a positive i32 value (explicit vector length) that is unknown at compile
Returns a non-negative i32 value (explicit vector length) that is unknown at compile
time and depends on the hardware specification.
If the result value does not fit in the result type, then the result is
a :ref:`poison value <poisonvalues>`.
Expand All @@ -19651,13 +19651,23 @@ 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.
Let ``%max_lanes`` be the number of lanes in the type described by ``%vf`` and
``%scalable``, here are the constraints on the returned value:

This intrinsic will only return 0 if the input count is also 0. A non-zero input
count will produce a non-zero result.
- If ``%cnt`` equals to 0, returns 0.
- The returned value is always less than or equal to ``%max_lanes``.
- The returned value is always greater than or equal to ``ceil(%cnt / ceil(%cnt / %max_lanes))``,
if ``%cnt`` is non-zero.
- The returned values are monotonically non-increasing in each loop iteration. That is,
the returned value of an iteration is at least as large as that of any later
iteration.

Note that it has the following implications:

- For a loop that uses this intrinsic, the number of iterations is equal to
``ceil(%C / %max_lanes)`` where ``%C`` is the initial ``%cnt`` value.
- If ``%cnt`` is non-zero, the return value is non-zero as well.
- If ``%cnt`` is less than or equal to ``%max_lanes``, the return value is equal to ``%cnt``.

'``llvm.experimental.vector.partial.reduce.add.*``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit e806370

Please sign in to comment.