Skip to content

Commit f844321

Browse files
Simon Mollmemfrob
authored andcommitted
[VP] Declaration and docs for vp.select intrinsic
llvm.vp.select extends the regular select instruction with an explicit vector length (%evl). All lanes with indexes at and above %evl are undefined. Lanes below %evl are taken from the first input where the mask is true and from the second input otherwise. Reviewed By: rogfer01 Differential Revision: https://reviews.llvm.org/D105351
1 parent 7c5bba0 commit f844321

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

llvm/docs/LangRef.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17745,6 +17745,64 @@ The use of an effective %evl is discouraged for those targets. The function
1774517745
``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target
1774617746
has native support for %evl.
1774717747

17748+
.. _int_vp_select:
17749+
17750+
'``llvm.vp.select.*``' Intrinsics
17751+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17752+
17753+
Syntax:
17754+
"""""""
17755+
This is an overloaded intrinsic.
17756+
17757+
::
17758+
17759+
declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>)
17760+
declare <vscale x 4 x i64> @llvm.vp.select.nxv4i64 (<vscale x 4 x i1> <condition>, <vscale x 4 x i32> <on_true>, <vscale x 4 x i32> <on_false>, i32 <evl>)
17761+
17762+
Overview:
17763+
"""""""""
17764+
17765+
The '``llvm.vp.select``' intrinsic is used to choose one value based on a
17766+
condition vector, without IR-level branching.
17767+
17768+
Arguments:
17769+
""""""""""
17770+
17771+
The first operand is a vector of ``i1`` and indicates the condition. The
17772+
second operand is the value that is selected where the condition vector is
17773+
true. The third operand is the value that is selected where the condition
17774+
vector is false. The vectors must be of the same size. The fourth operand is
17775+
the explicit vector length.
17776+
17777+
#. The optional ``fast-math flags`` marker indicates that the select has one or
17778+
more :ref:`fast-math flags <fastmath>`. These are optimization hints to
17779+
enable otherwise unsafe floating-point optimizations. Fast-math flags are
17780+
only valid for selects that return a floating-point scalar or vector type,
17781+
or an array (nested to any depth) of floating-point scalar or vector types.
17782+
17783+
Semantics:
17784+
""""""""""
17785+
17786+
The intrinsic selects lanes from the second and third operand depending on a
17787+
condition vector.
17788+
17789+
All result lanes at positions greater or equal than ``%evl`` are undefined.
17790+
For all lanes below ``%evl`` where the condition vector is true the lane is
17791+
taken from the second operand. Otherwise, the lane is taken from the third
17792+
operand.
17793+
17794+
Example:
17795+
""""""""
17796+
17797+
.. code-block:: llvm
17798+
17799+
%r = call <4 x i32> @llvm.vp.select.v4i32(<4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false, i32 %evl)
17800+
17801+
;;; Expansion.
17802+
;; Any result is legal on lanes at and above %evl.
17803+
%also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false
17804+
17805+
1774817806

1774917807
.. _int_vp_add:
1775017808

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,12 @@ let IntrProperties =
15071507
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
15081508
llvm_i32_ty]>;
15091509
}
1510+
// Shuffles.
1511+
def int_vp_select : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1512+
[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1513+
LLVMMatchType<0>,
1514+
LLVMMatchType<0>,
1515+
llvm_i32_ty]>;
15101516

15111517
// Reductions
15121518
let IntrProperties = [IntrSpeculatable, IntrNoMem, IntrNoSync, IntrWillReturn] in {

llvm/include/llvm/IR/VPIntrinsics.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ HELPER_REGISTER_REDUCTION_SEQ_VP(vp_reduce_fmul, VP_REDUCE_FMUL,
333333

334334
///// } Reduction
335335

336+
///// Shuffles {
337+
338+
// llvm.vp.select(mask,on_true,on_false,vlen)
339+
BEGIN_REGISTER_VP_INTRINSIC(vp_select, 0, 3)
340+
// BEGIN_REGISTER_VP_SDNODE(VP_SELECT, -1, vp_select, 0, 4)
341+
// END_REGISTER_CASES(vp_select, VP_SELECT)
342+
END_REGISTER_VP_INTRINSIC(vp_select)
343+
344+
///// } Shuffles
345+
336346
#undef BEGIN_REGISTER_VP
337347
#undef BEGIN_REGISTER_VP_INTRINSIC
338348
#undef BEGIN_REGISTER_VP_SDNODE

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
482482
VPFunc = Intrinsic::getDeclaration(M, VPID, OverloadTy);
483483
break;
484484
}
485+
case Intrinsic::vp_select:
486+
VPFunc = Intrinsic::getDeclaration(M, VPID, {Params[1]->getType()});
487+
break;
485488
case Intrinsic::vp_load:
486489
VPFunc = Intrinsic::getDeclaration(
487490
M, VPID,

llvm/unittests/IR/VPIntrinsicTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class VPIntrinsicTest : public testing::Test {
6868
Str << " declare float @llvm.vp.reduce." << ReductionOpcode
6969
<< ".v8f32(float, <8 x float>, <8 x i1>, i32) ";
7070

71+
Str << " declare <8 x i32> @llvm.vp.select.v8i32(<8 x i1>, <8 x i32>, <8 x "
72+
"i32>, i32)";
7173
return parseAssemblyString(Str.str(), Err, C);
7274
}
7375
};

0 commit comments

Comments
 (0)