[llvm] fb2233e - [LangRef] Move mask intrinsics out of VP section (#201282)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 04:45:48 PDT 2026
Author: Luke Lau
Date: 2026-06-03T11:45:43Z
New Revision: fb2233e688d089b1d7bf9a8032cd92a6de2ae213
URL: https://github.com/llvm/llvm-project/commit/fb2233e688d089b1d7bf9a8032cd92a6de2ae213
DIFF: https://github.com/llvm/llvm-project/commit/fb2233e688d089b1d7bf9a8032cd92a6de2ae213.diff
LOG: [LangRef] Move mask intrinsics out of VP section (#201282)
Somehow llvm.get.active.lane.mask and
llvm.loop.dependence.{war,raw}.mask ended up in the VP intrinsics
section of the LangRef. This PR pulls them out into a new "Vector Mask
Intrinsics" section.
Added:
Modified:
llvm/docs/LangRef.rst
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d998b6a66e168..7a6fc0641fa41 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -21721,6 +21721,267 @@ Arguments:
None.
+Vector Mask Intrinsics
+----------------------
+
+.. _int_get_active_lane_mask:
+
+'``llvm.get.active.lane.mask.*``' Intrinsics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+This is an overloaded intrinsic.
+
+::
+
+ declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
+ declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
+ declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
+ declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
+
+
+Overview:
+"""""""""
+
+Create a mask representing active and inactive vector lanes.
+
+
+Arguments:
+""""""""""
+
+Both arguments have the same scalar integer type. The result is a vector with
+the i1 element type.
+
+Semantics:
+""""""""""
+
+The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
+to:
+
+::
+
+ %m[i] = icmp ult (%base + i), %n
+
+where ``%m`` is a vector (mask) of active/inactive lanes with its elements
+indexed by ``i``, and ``%base``, ``%n`` are the two arguments to
+``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
+the unsigned less-than comparison operator. Overflow cannot occur in
+``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
+numbers and not in machine numbers. The above is equivalent to:
+
+::
+
+ %m = @llvm.get.active.lane.mask(%base, %n)
+
+This can, for example, be emitted by the loop vectorizer in which case
+``%base`` is the first element of the vector induction variable (VIV) and
+``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
+less than comparison of VIV with the loop tripcount, producing a mask of
+true/false values representing active/inactive vector lanes, except if the VIV
+overflows in which case they return false in the lanes where the VIV overflows.
+The arguments are scalar types to accommodate scalable vector types, for which
+it is unknown what the type of the step vector needs to be that enumerate its
+lanes without overflow.
+
+This mask ``%m`` can e.g., be used in masked load/store instructions. These
+intrinsics provide a hint to the backend. I.e., for a vector loop, the
+back-edge taken count of the original scalar loop is explicit as the second
+argument.
+
+
+Examples:
+"""""""""
+
+.. code-block:: llvm
+
+ %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
+ %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(ptr align 4 %3, <4 x i1> %active.lane.mask, <4 x i32> poison)
+
+
+.. _int_loop_dependence_war_mask:
+
+'``llvm.loop.dependence.war.mask.*``' Intrinsics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+This is an overloaded intrinsic.
+
+::
+
+ declare <4 x i1> @llvm.loop.dependence.war.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+ declare <8 x i1> @llvm.loop.dependence.war.mask.v8i1.i32(i32 %addrA, i32 %addrB, i32 immarg %elementSize)
+ declare <16 x i1> @llvm.loop.dependence.war.mask.v16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+ declare <vscale x 16 x i1> @llvm.loop.dependence.war.mask.nxv16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+
+
+Overview:
+"""""""""
+
+Given a vector load from address %addrA followed by a vector store to address
+%addrB, this instruction generates a mask where an active lane indicates that
+the write-after-read sequence can be performed safely for that lane, without the
+danger of a write-after-read hazard occurring.
+
+A write-after-read hazard occurs when a write-after-read sequence for a given
+lane in a vector ends up being executed as a read-after-write sequence due to
+the aliasing of pointers.
+
+Arguments:
+""""""""""
+
+The first two arguments are integers and the last argument is an immediate.
+The result is a vector with the i1 element type.
+
+Semantics:
+""""""""""
+
+``%elementSize`` is the size of the accessed elements in bytes.
+The intrinsic returns ``poison`` if the distance between ``%addrA`` and ``%addrB``
+is smaller than ``VF * %elementsize`` and either ``%addrA + VF * %elementSize``
+or ``%addrB + VF * %elementSize`` wrap.
+
+The element of the result mask is active when loading from %addrA then storing to
+%addrB is safe and doesn't result in a write-after-read hazard, meaning that:
+
+* (addrB - addrA) <= 0 (guarantees that all lanes are loaded before any stores), or
+* elementSize * lane < (addrB - addrA) (guarantees that this lane is loaded
+ before the store to the same address)
+
+Examples:
+"""""""""
+
+.. code-block:: llvm
+
+ %addrA = ptrtoaddr ptr %ptrA to i64
+ %addrB = ptrtoaddr ptr %ptrB to i64
+ %loop.dependence.mask = call <4 x i1> @llvm.loop.dependence.war.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 4)
+ %vecA = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr align 4 %ptrA, <4 x i1> %loop.dependence.mask, <4 x i32> poison)
+ [...]
+ call @llvm.masked.store.v4i32.p0(<4 x i32> %vecA, ptr align 4 %ptrB, <4 x i1> %loop.dependence.mask)
+
+ ; For the above example, consider the following cases:
+ ;
+ ; 1. addrA >= addrB
+ ;
+ ; load = <0,1,2,3> ; uint32_t load = array[i+2];
+ ; store = <0,1,2,3> ; array[i] = store;
+ ;
+ ; This results in an all-true mask, as the load always occurs before the
+ ; store, so it does not depend on any values to be stored.
+ ;
+ ; 2. addrB - addrA = 2 * elementSize:
+ ;
+ ; load = <0,1,2,3> ; uint32_t load = array[i];
+ ; store = <0,1,2,3> ; array[i+2] = store;
+ ;
+ ; This results in a mask with the first two lanes active. This is because
+ ; we can only read two lanes before we would read values that have yet to
+ ; be written.
+ ;
+ ; 3. addrB - addrA = 4 * elementSize
+ ;
+ ; load = <0,1,2,3> ; uint32_t load = array[i];
+ ; store = <0,1,2,3> ; array[i+4] = store;
+ ;
+ ; This results in an all-true mask, as the store is a full vector ahead
+ ; of the load, so all values will be written before any lane is read.
+
+.. _int_loop_dependence_raw_mask:
+
+'``llvm.loop.dependence.raw.mask.*``' Intrinsics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+This is an overloaded intrinsic.
+
+::
+
+ declare <4 x i1> @llvm.loop.dependence.raw.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+ declare <8 x i1> @llvm.loop.dependence.raw.mask.v8i1.i32(i32 %addrA, i32 %addrB, i32 immarg %elementSize)
+ declare <16 x i1> @llvm.loop.dependence.raw.mask.v16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+ declare <vscale x 16 x i1> @llvm.loop.dependence.raw.mask.nxv16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
+
+
+Overview:
+"""""""""
+
+Given a vector store to address %addrA followed by a vector load from address
+%addrB, this instruction generates a mask where an active lane indicates that the
+read-after-write sequence can be performed safely for that lane, without a
+read-after-write hazard or a store-to-load forwarding hazard being introduced.
+
+A read-after-write hazard occurs when a read-after-write sequence for a given
+lane in a vector ends up being executed as a write-after-read sequence due to
+the aliasing of pointers.
+
+A store-to-load forwarding hazard occurs when a vector store writes to an
+address that partially overlaps with the address of a subsequent vector load,
+meaning that the vector load can't be performed until the vector store is
+complete.
+
+Arguments:
+""""""""""
+
+The first two arguments are integers and the last argument is an immediate.
+The result is a vector with the i1 element type.
+
+Semantics:
+""""""""""
+
+``%elementSize`` is the size of the accessed elements in bytes.
+The intrinsic returns ``poison`` if the distance between ``%addrA`` and ``%addrB``
+is smaller than ``VF * %elementsize`` and either ``%addrA + VF * %elementSize``
+or ``%addrB + VF * %elementSize`` wrap.
+
+The element of the result mask is active when storing to %addrA then loading from
+%addrB is safe and doesn't result in aliasing, meaning that:
+
+* elementSize * lane < abs(addrB - addrA) (guarantees that the store of this lane
+ occurs before loading from this address), or
+* addrA == addrB (doesn't introduce any new hazards that weren't in the scalar
+ code)
+
+Examples:
+"""""""""
+
+.. code-block:: llvm
+
+ %addrA = ptrtoaddr ptr %ptrA to i64
+ %addrB = ptrtoaddr ptr %ptrB to i64
+ %loop.dependence.mask = call <4 x i1> @llvm.loop.dependence.raw.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 4)
+ call @llvm.masked.store.v4i32.p0(<4 x i32> %vecA, ptr align 4 %ptrA, <4 x i1> %loop.dependence.mask)
+ [...]
+ %vecB = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr align 4 %ptrB, <4 x i1> %loop.dependence.mask, <4 x i32> poison)
+
+ ; For the above example, consider the following cases:
+ ;
+ ; 1. addrA == addrB
+ ;
+ ; store = <0,1,2,3> ; array[i] = store;
+ ; load = <0,1,2,3> ; uint32_t load = array[i];
+ ;
+ ; This results in a all-true mask. There is no conflict.
+ ;
+ ; 2. addrB - addrA = 2 * elementSize
+ ;
+ ; store = <0,1,2,3> ; array[i] = store;
+ ; load = <0,1,2,3> ; uint32_t load = array[i+2];
+ ;
+ ; This results in a mask with the first two lanes active. In this case,
+ ; only two lanes can be written without overwriting values yet to be read.
+ ;
+ ; 3. addrB - addrA = -2 * elementSize
+ ;
+ ; store = <0,1,2,3> ; array[i+2] = store;
+ ; load = <0,1,2,3> ; uint32_t load = array[i];
+ ;
+ ; This also results in a mask with the first two lanes active. This is
+ ; because if any more lanes were active the load would be dependent on the
+ ; completion of the store.
+
Experimental Vector Intrinsics
------------------------------
@@ -25139,274 +25400,59 @@ Overview:
"""""""""
Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
-value, returning the result as a scalar.
-
-
-Arguments:
-""""""""""
-
-The first argument is the start value of the reduction, which must be a scalar
-floating-point type equal to the result type. The second argument is the vector
-on which the reduction is performed and must be a vector of floating-point
-values whose element type is the result/start type. The third argument is the
-vector mask and is a vector of boolean values with the same number of elements
-as the vector argument. The fourth argument is the explicit vector length of the
-operation.
-
-Semantics:
-""""""""""
-
-The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
-reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
-vector argument ``val`` on each enabled lane, taking the minimum of that and the
-scalar ``start_value``. Disabled lanes are treated as containing the neutral
-value (i.e., having no effect on the reduction operation). If the vector length
-is zero, the result is the start value.
-
-The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
-flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are
-both set, then the neutral value is the largest floating-point value for the
-result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
-
-This instruction has the same comparison semantics as the
-:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
-'``llvm.minnum.*``' intrinsic).
-
-To ignore the start value, the neutral value can be used.
-
-Examples:
-"""""""""
-
-.. code-block:: llvm
-
- %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
- ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
- ; are treated as though %mask were false for those lanes.
-
- %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
- %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
- %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
-
-
-.. _int_vp_reduce_fmaximum:
-
-'``llvm.vp.reduce.fmaximum.*``' Intrinsics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Syntax:
-"""""""
-This is an overloaded intrinsic.
-
-::
-
- declare float @llvm.vp.reduce.fmaximum.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
- declare double @llvm.vp.reduce.fmaximum.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
-
-Overview:
-"""""""""
-
-Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
-value, returning the result as a scalar.
-
-
-Arguments:
-""""""""""
-
-The first argument is the start value of the reduction, which must be a scalar
-floating-point type equal to the result type. The second argument is the vector
-on which the reduction is performed and must be a vector of floating-point
-values whose element type is the result/start type. The third argument is the
-vector mask and is a vector of boolean values with the same number of elements
-as the vector argument. The fourth argument is the explicit vector length of the
-operation.
-
-Semantics:
-""""""""""
-
-The '``llvm.vp.reduce.fmaximum``' intrinsic performs the floating-point ``MAX``
-reduction (:ref:`llvm.vector.reduce.fmaximum <int_vector_reduce_fmaximum>`) of
-the vector argument ``val`` on each enabled lane, taking the maximum of that and
-the scalar ``start_value``. Disabled lanes are treated as containing the
-neutral value (i.e., having no effect on the reduction operation). If the vector
-length is zero, the result is the start value.
-
-The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
-flags are set or only the ``nnan`` is set, the neutral value is ``-Infinity``.
-If ``ninf`` is set, then the neutral value is the smallest floating-point value
-for the result type.
-
-This instruction has the same comparison semantics as the
-:ref:`llvm.vector.reduce.fmaximum <int_vector_reduce_fmaximum>` intrinsic (and
-thus the '``llvm.maximum.*``' intrinsic). That is, the result will always be a
-number unless any of the elements in the vector or the starting value is
-``NaN``. Namely, this intrinsic propagates ``NaN``. Also, -0.0 is considered
-less than +0.0.
-
-To ignore the start value, the neutral value can be used.
-
-Examples:
-"""""""""
-
-.. code-block:: llvm
-
- %r = call float @llvm.vp.reduce.fmaximum.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
- ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
- ; are treated as though %mask were false for those lanes.
-
- %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float -infinity, float -infinity, float -infinity, float -infinity>
- %reduction = call float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> %masked.a)
- %also.r = call float @llvm.maximum.f32(float %reduction, float %start)
-
-
-.. _int_vp_reduce_fminimum:
-
-'``llvm.vp.reduce.fminimum.*``' Intrinsics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Syntax:
-"""""""
-This is an overloaded intrinsic.
-
-::
-
- declare float @llvm.vp.reduce.fminimum.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
- declare double @llvm.vp.reduce.fminimum.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
-
-Overview:
-"""""""""
-
-Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
-value, returning the result as a scalar.
-
-
-Arguments:
-""""""""""
-
-The first argument is the start value of the reduction, which must be a scalar
-floating-point type equal to the result type. The second argument is the vector
-on which the reduction is performed and must be a vector of floating-point
-values whose element type is the result/start type. The third argument is the
-vector mask and is a vector of boolean values with the same number of elements
-as the vector argument. The fourth argument is the explicit vector length of the
-operation.
-
-Semantics:
-""""""""""
-
-The '``llvm.vp.reduce.fminimum``' intrinsic performs the floating-point ``MIN``
-reduction (:ref:`llvm.vector.reduce.fminimum <int_vector_reduce_fminimum>`) of
-the vector argument ``val`` on each enabled lane, taking the minimum of that and
-the scalar ``start_value``. Disabled lanes are treated as containing the neutral
-value (i.e., having no effect on the reduction operation). If the vector length
-is zero, the result is the start value.
-
-The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
-flags are set or only the ``nnan`` is set, the neutral value is ``+Infinity``.
-If ``ninf`` is set, then the neutral value is the largest floating-point value
-for the result type.
-
-This instruction has the same comparison semantics as the
-:ref:`llvm.vector.reduce.fminimum <int_vector_reduce_fminimum>` intrinsic (and
-thus the '``llvm.minimum.*``' intrinsic). That is, the result will always be a
-number unless any of the elements in the vector or the starting value is
-``NaN``. Namely, this intrinsic propagates ``NaN``. Also, -0.0 is considered
-less than +0.0.
-
-To ignore the start value, the neutral value can be used.
-
-Examples:
-"""""""""
-
-.. code-block:: llvm
-
- %r = call float @llvm.vp.reduce.fminimum.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
- ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
- ; are treated as though %mask were false for those lanes.
-
- %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float infinity, float infinity, float infinity, float infinity>
- %reduction = call float @llvm.vector.reduce.fminimum.v4f32(<4 x float> %masked.a)
- %also.r = call float @llvm.minimum.f32(float %reduction, float %start)
-
-
-.. _int_get_active_lane_mask:
-
-'``llvm.get.active.lane.mask.*``' Intrinsics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Syntax:
-"""""""
-This is an overloaded intrinsic.
-
-::
-
- declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
- declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
- declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
- declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
-
-
-Overview:
-"""""""""
-
-Create a mask representing active and inactive vector lanes.
-
-
-Arguments:
-""""""""""
-
-Both arguments have the same scalar integer type. The result is a vector with
-the i1 element type.
-
-Semantics:
-""""""""""
-
-The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
-to:
+value, returning the result as a scalar.
-::
- %m[i] = icmp ult (%base + i), %n
+Arguments:
+""""""""""
-where ``%m`` is a vector (mask) of active/inactive lanes with its elements
-indexed by ``i``, and ``%base``, ``%n`` are the two arguments to
-``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
-the unsigned less-than comparison operator. Overflow cannot occur in
-``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
-numbers and not in machine numbers. The above is equivalent to:
+The first argument is the start value of the reduction, which must be a scalar
+floating-point type equal to the result type. The second argument is the vector
+on which the reduction is performed and must be a vector of floating-point
+values whose element type is the result/start type. The third argument is the
+vector mask and is a vector of boolean values with the same number of elements
+as the vector argument. The fourth argument is the explicit vector length of the
+operation.
-::
+Semantics:
+""""""""""
- %m = @llvm.get.active.lane.mask(%base, %n)
+The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
+reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
+vector argument ``val`` on each enabled lane, taking the minimum of that and the
+scalar ``start_value``. Disabled lanes are treated as containing the neutral
+value (i.e., having no effect on the reduction operation). If the vector length
+is zero, the result is the start value.
-This can, for example, be emitted by the loop vectorizer in which case
-``%base`` is the first element of the vector induction variable (VIV) and
-``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
-less than comparison of VIV with the loop tripcount, producing a mask of
-true/false values representing active/inactive vector lanes, except if the VIV
-overflows in which case they return false in the lanes where the VIV overflows.
-The arguments are scalar types to accommodate scalable vector types, for which
-it is unknown what the type of the step vector needs to be that enumerate its
-lanes without overflow.
+The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
+flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are
+both set, then the neutral value is the largest floating-point value for the
+result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
-This mask ``%m`` can e.g., be used in masked load/store instructions. These
-intrinsics provide a hint to the backend. I.e., for a vector loop, the
-back-edge taken count of the original scalar loop is explicit as the second
-argument.
+This instruction has the same comparison semantics as the
+:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
+'``llvm.minnum.*``' intrinsic).
+To ignore the start value, the neutral value can be used.
Examples:
"""""""""
.. code-block:: llvm
- %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
- %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(ptr align 4 %3, <4 x i1> %active.lane.mask, <4 x i32> poison)
+ %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
+ ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
+ ; are treated as though %mask were false for those lanes.
+
+ %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
+ %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
+ %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
-.. _int_loop_dependence_war_mask:
+.. _int_vp_reduce_fmaximum:
-'``llvm.loop.dependence.war.mask.*``' Intrinsics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+'``llvm.vp.reduce.fmaximum.*``' Intrinsics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Syntax:
"""""""
@@ -25414,88 +25460,69 @@ This is an overloaded intrinsic.
::
- declare <4 x i1> @llvm.loop.dependence.war.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
- declare <8 x i1> @llvm.loop.dependence.war.mask.v8i1.i32(i32 %addrA, i32 %addrB, i32 immarg %elementSize)
- declare <16 x i1> @llvm.loop.dependence.war.mask.v16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
- declare <vscale x 16 x i1> @llvm.loop.dependence.war.mask.nxv16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
-
+ declare float @llvm.vp.reduce.fmaximum.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
+ declare double @llvm.vp.reduce.fmaximum.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
Overview:
"""""""""
-Given a vector load from address %addrA followed by a vector store to address
-%addrB, this instruction generates a mask where an active lane indicates that
-the write-after-read sequence can be performed safely for that lane, without the
-danger of a write-after-read hazard occurring.
+Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
+value, returning the result as a scalar.
-A write-after-read hazard occurs when a write-after-read sequence for a given
-lane in a vector ends up being executed as a read-after-write sequence due to
-the aliasing of pointers.
Arguments:
""""""""""
-The first two arguments are integers and the last argument is an immediate.
-The result is a vector with the i1 element type.
+The first argument is the start value of the reduction, which must be a scalar
+floating-point type equal to the result type. The second argument is the vector
+on which the reduction is performed and must be a vector of floating-point
+values whose element type is the result/start type. The third argument is the
+vector mask and is a vector of boolean values with the same number of elements
+as the vector argument. The fourth argument is the explicit vector length of the
+operation.
Semantics:
""""""""""
-``%elementSize`` is the size of the accessed elements in bytes.
-The intrinsic returns ``poison`` if the distance between ``%addrA`` and ``%addrB``
-is smaller than ``VF * %elementsize`` and either ``%addrA + VF * %elementSize``
-or ``%addrB + VF * %elementSize`` wrap.
+The '``llvm.vp.reduce.fmaximum``' intrinsic performs the floating-point ``MAX``
+reduction (:ref:`llvm.vector.reduce.fmaximum <int_vector_reduce_fmaximum>`) of
+the vector argument ``val`` on each enabled lane, taking the maximum of that and
+the scalar ``start_value``. Disabled lanes are treated as containing the
+neutral value (i.e., having no effect on the reduction operation). If the vector
+length is zero, the result is the start value.
-The element of the result mask is active when loading from %addrA then storing to
-%addrB is safe and doesn't result in a write-after-read hazard, meaning that:
+The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
+flags are set or only the ``nnan`` is set, the neutral value is ``-Infinity``.
+If ``ninf`` is set, then the neutral value is the smallest floating-point value
+for the result type.
-* (addrB - addrA) <= 0 (guarantees that all lanes are loaded before any stores), or
-* elementSize * lane < (addrB - addrA) (guarantees that this lane is loaded
- before the store to the same address)
+This instruction has the same comparison semantics as the
+:ref:`llvm.vector.reduce.fmaximum <int_vector_reduce_fmaximum>` intrinsic (and
+thus the '``llvm.maximum.*``' intrinsic). That is, the result will always be a
+number unless any of the elements in the vector or the starting value is
+``NaN``. Namely, this intrinsic propagates ``NaN``. Also, -0.0 is considered
+less than +0.0.
+
+To ignore the start value, the neutral value can be used.
Examples:
"""""""""
.. code-block:: llvm
- %addrA = ptrtoaddr ptr %ptrA to i64
- %addrB = ptrtoaddr ptr %ptrB to i64
- %loop.dependence.mask = call <4 x i1> @llvm.loop.dependence.war.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 4)
- %vecA = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr align 4 %ptrA, <4 x i1> %loop.dependence.mask, <4 x i32> poison)
- [...]
- call @llvm.masked.store.v4i32.p0(<4 x i32> %vecA, ptr align 4 %ptrB, <4 x i1> %loop.dependence.mask)
+ %r = call float @llvm.vp.reduce.fmaximum.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
+ ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
+ ; are treated as though %mask were false for those lanes.
- ; For the above example, consider the following cases:
- ;
- ; 1. addrA >= addrB
- ;
- ; load = <0,1,2,3> ; uint32_t load = array[i+2];
- ; store = <0,1,2,3> ; array[i] = store;
- ;
- ; This results in an all-true mask, as the load always occurs before the
- ; store, so it does not depend on any values to be stored.
- ;
- ; 2. addrB - addrA = 2 * elementSize:
- ;
- ; load = <0,1,2,3> ; uint32_t load = array[i];
- ; store = <0,1,2,3> ; array[i+2] = store;
- ;
- ; This results in a mask with the first two lanes active. This is because
- ; we can only read two lanes before we would read values that have yet to
- ; be written.
- ;
- ; 3. addrB - addrA = 4 * elementSize
- ;
- ; load = <0,1,2,3> ; uint32_t load = array[i];
- ; store = <0,1,2,3> ; array[i+4] = store;
- ;
- ; This results in an all-true mask, as the store is a full vector ahead
- ; of the load, so all values will be written before any lane is read.
+ %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float -infinity, float -infinity, float -infinity, float -infinity>
+ %reduction = call float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> %masked.a)
+ %also.r = call float @llvm.maximum.f32(float %reduction, float %start)
-.. _int_loop_dependence_raw_mask:
-'``llvm.loop.dependence.raw.mask.*``' Intrinsics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+.. _int_vp_reduce_fminimum:
+
+'``llvm.vp.reduce.fminimum.*``' Intrinsics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Syntax:
"""""""
@@ -25503,88 +25530,63 @@ This is an overloaded intrinsic.
::
- declare <4 x i1> @llvm.loop.dependence.raw.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
- declare <8 x i1> @llvm.loop.dependence.raw.mask.v8i1.i32(i32 %addrA, i32 %addrB, i32 immarg %elementSize)
- declare <16 x i1> @llvm.loop.dependence.raw.mask.v16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
- declare <vscale x 16 x i1> @llvm.loop.dependence.raw.mask.nxv16i1.i64(i64 %addrA, i64 %addrB, i64 immarg %elementSize)
-
+ declare float @llvm.vp.reduce.fminimum.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
+ declare double @llvm.vp.reduce.fminimum.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
Overview:
"""""""""
-Given a vector store to address %addrA followed by a vector load from address
-%addrB, this instruction generates a mask where an active lane indicates that the
-read-after-write sequence can be performed safely for that lane, without a
-read-after-write hazard or a store-to-load forwarding hazard being introduced.
-
-A read-after-write hazard occurs when a read-after-write sequence for a given
-lane in a vector ends up being executed as a write-after-read sequence due to
-the aliasing of pointers.
+Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
+value, returning the result as a scalar.
-A store-to-load forwarding hazard occurs when a vector store writes to an
-address that partially overlaps with the address of a subsequent vector load,
-meaning that the vector load can't be performed until the vector store is
-complete.
Arguments:
""""""""""
-The first two arguments are integers and the last argument is an immediate.
-The result is a vector with the i1 element type.
+The first argument is the start value of the reduction, which must be a scalar
+floating-point type equal to the result type. The second argument is the vector
+on which the reduction is performed and must be a vector of floating-point
+values whose element type is the result/start type. The third argument is the
+vector mask and is a vector of boolean values with the same number of elements
+as the vector argument. The fourth argument is the explicit vector length of the
+operation.
Semantics:
""""""""""
-``%elementSize`` is the size of the accessed elements in bytes.
-The intrinsic returns ``poison`` if the distance between ``%addrA`` and ``%addrB``
-is smaller than ``VF * %elementsize`` and either ``%addrA + VF * %elementSize``
-or ``%addrB + VF * %elementSize`` wrap.
+The '``llvm.vp.reduce.fminimum``' intrinsic performs the floating-point ``MIN``
+reduction (:ref:`llvm.vector.reduce.fminimum <int_vector_reduce_fminimum>`) of
+the vector argument ``val`` on each enabled lane, taking the minimum of that and
+the scalar ``start_value``. Disabled lanes are treated as containing the neutral
+value (i.e., having no effect on the reduction operation). If the vector length
+is zero, the result is the start value.
-The element of the result mask is active when storing to %addrA then loading from
-%addrB is safe and doesn't result in aliasing, meaning that:
+The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
+flags are set or only the ``nnan`` is set, the neutral value is ``+Infinity``.
+If ``ninf`` is set, then the neutral value is the largest floating-point value
+for the result type.
-* elementSize * lane < abs(addrB - addrA) (guarantees that the store of this lane
- occurs before loading from this address), or
-* addrA == addrB (doesn't introduce any new hazards that weren't in the scalar
- code)
+This instruction has the same comparison semantics as the
+:ref:`llvm.vector.reduce.fminimum <int_vector_reduce_fminimum>` intrinsic (and
+thus the '``llvm.minimum.*``' intrinsic). That is, the result will always be a
+number unless any of the elements in the vector or the starting value is
+``NaN``. Namely, this intrinsic propagates ``NaN``. Also, -0.0 is considered
+less than +0.0.
+
+To ignore the start value, the neutral value can be used.
Examples:
"""""""""
.. code-block:: llvm
- %addrA = ptrtoaddr ptr %ptrA to i64
- %addrB = ptrtoaddr ptr %ptrB to i64
- %loop.dependence.mask = call <4 x i1> @llvm.loop.dependence.raw.mask.v4i1.i64(i64 %addrA, i64 %addrB, i64 4)
- call @llvm.masked.store.v4i32.p0(<4 x i32> %vecA, ptr align 4 %ptrA, <4 x i1> %loop.dependence.mask)
- [...]
- %vecB = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr align 4 %ptrB, <4 x i1> %loop.dependence.mask, <4 x i32> poison)
+ %r = call float @llvm.vp.reduce.fminimum.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
+ ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
+ ; are treated as though %mask were false for those lanes.
- ; For the above example, consider the following cases:
- ;
- ; 1. addrA == addrB
- ;
- ; store = <0,1,2,3> ; array[i] = store;
- ; load = <0,1,2,3> ; uint32_t load = array[i];
- ;
- ; This results in a all-true mask. There is no conflict.
- ;
- ; 2. addrB - addrA = 2 * elementSize
- ;
- ; store = <0,1,2,3> ; array[i] = store;
- ; load = <0,1,2,3> ; uint32_t load = array[i+2];
- ;
- ; This results in a mask with the first two lanes active. In this case,
- ; only two lanes can be written without overwriting values yet to be read.
- ;
- ; 3. addrB - addrA = -2 * elementSize
- ;
- ; store = <0,1,2,3> ; array[i+2] = store;
- ; load = <0,1,2,3> ; uint32_t load = array[i];
- ;
- ; This also results in a mask with the first two lanes active. This is
- ; because if any more lanes were active the load would be dependent on the
- ; completion of the store.
+ %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float infinity, float infinity, float infinity, float infinity>
+ %reduction = call float @llvm.vector.reduce.fminimum.v4f32(<4 x float> %masked.a)
+ %also.r = call float @llvm.minimum.f32(float %reduction, float %start)
.. _int_experimental_vp_splice:
More information about the llvm-commits
mailing list