Skip to content

Commit e806370

Browse files
mshockwavetopperc
andauthored
[LangRef] Update the semantic of experimental.get.vector.length (#104475)
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 <craig.topper@sifive.com>
1 parent d880f5a commit e806370

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

llvm/docs/LangRef.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19641,7 +19641,7 @@ vectorization factor should be multiplied by vscale.
1964119641
Semantics:
1964219642
""""""""""
1964319643

19644-
Returns a positive i32 value (explicit vector length) that is unknown at compile
19644+
Returns a non-negative i32 value (explicit vector length) that is unknown at compile
1964519645
time and depends on the hardware specification.
1964619646
If the result value does not fit in the result type, then the result is
1964719647
a :ref:`poison value <poisonvalues>`.
@@ -19651,13 +19651,23 @@ in order to get the number of elements to process on each loop iteration. The
1965119651
result should be used to decrease the count for the next iteration until the
1965219652
count reaches zero.
1965319653

19654-
If the count is larger than the number of lanes in the type described by the
19655-
last 2 arguments, this intrinsic may return a value less than the number of
19656-
lanes implied by the type. The result will be at least as large as the result
19657-
will be on any later loop iteration.
19654+
Let ``%max_lanes`` be the number of lanes in the type described by ``%vf`` and
19655+
``%scalable``, here are the constraints on the returned value:
1965819656

19659-
This intrinsic will only return 0 if the input count is also 0. A non-zero input
19660-
count will produce a non-zero result.
19657+
- If ``%cnt`` equals to 0, returns 0.
19658+
- The returned value is always less than or equal to ``%max_lanes``.
19659+
- The returned value is always greater than or equal to ``ceil(%cnt / ceil(%cnt / %max_lanes))``,
19660+
if ``%cnt`` is non-zero.
19661+
- The returned values are monotonically non-increasing in each loop iteration. That is,
19662+
the returned value of an iteration is at least as large as that of any later
19663+
iteration.
19664+
19665+
Note that it has the following implications:
19666+
19667+
- For a loop that uses this intrinsic, the number of iterations is equal to
19668+
``ceil(%C / %max_lanes)`` where ``%C`` is the initial ``%cnt`` value.
19669+
- If ``%cnt`` is non-zero, the return value is non-zero as well.
19670+
- If ``%cnt`` is less than or equal to ``%max_lanes``, the return value is equal to ``%cnt``.
1966119671

1966219672
'``llvm.experimental.vector.partial.reduce.add.*``' Intrinsic
1966319673
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)