Skip to content

Commit c35b219

Browse files
committed
Initial working version via scalarization
1 parent 0aec4d2 commit c35b219

File tree

4 files changed

+722
-0
lines changed

4 files changed

+722
-0
lines changed

llvm/docs/LangRef.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19956,6 +19956,36 @@ the follow sequence of operations:
1995619956

1995719957
The ``mask`` operand will apply to at least the gather and scatter operations.
1995819958

19959+
'``llvm.experimental.vector.masked.extract.last.active``' Intrinsic
19960+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19961+
19962+
This is an overloaded intrinsic.
19963+
19964+
This intrinsic will extract the value from a single lane of a vector, based
19965+
on a supplied mask vector.
19966+
19967+
::
19968+
19969+
declare i32 @llvm.experimental.vector.masked.extract.last.active.v4i32(<4 x i32> %data, <4 x i1> %mask, i32 %passthru)
19970+
declare i16 @llvm.experimental.vector.masked.extract.last.active.nxv8i16(<vscale x 8 x i16> %data, <vscale x 8 x i1> %mask, i16 %passthru)
19971+
19972+
Arguments:
19973+
""""""""""
19974+
19975+
The first argument is the data vector to extract a lane from. The second is a
19976+
mask vector controlling the extraction. The third argument is a passthru
19977+
value.
19978+
19979+
The two input vectors must have the same number of elements, and the type of
19980+
the passthru value must match that of the elements of the data vector.
19981+
19982+
Semantics:
19983+
""""""""""
19984+
19985+
The '``llvm.experimental.vector.masked.extract.last.active``' intrinsic will
19986+
find the index of the most significant active lane in the mask vector, and
19987+
extract the element at that index in the corresponding data vector. If no mask
19988+
lanes are active then the passthru value is returned instead.
1995919989

1996019990
.. _int_vector_compress:
1996119991

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,12 @@ def int_experimental_vector_histogram_add : DefaultAttrsIntrinsic<[],
19181918
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>], // Mask
19191919
[ IntrArgMemOnly ]>;
19201920

1921+
// Extract based on mask bits
1922+
def int_experimental_vector_masked_extract_last_active:
1923+
DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
1924+
[llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1925+
LLVMVectorElementType<0>], [IntrNoMem]>;
1926+
19211927
// Operators
19221928
let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
19231929
// Integer arithmetic

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8187,6 +8187,29 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
81878187
visitVectorHistogram(I, Intrinsic);
81888188
return;
81898189
}
8190+
case Intrinsic::experimental_vector_masked_extract_last_active: {
8191+
SDValue Data = getValue(I.getOperand(0));
8192+
SDValue Mask = getValue(I.getOperand(1));
8193+
SDValue PassThru = getValue(I.getOperand(2));
8194+
8195+
EVT DataVT = Data.getValueType();
8196+
EVT ScalarVT = PassThru.getValueType();
8197+
EVT BoolVT = Mask.getValueType().getScalarType();
8198+
EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
8199+
EVT IdxVecVT = DataVT.changeVectorElementType(IdxVT);
8200+
8201+
SDValue Zeroes = DAG.getConstant(0, sdl, IdxVecVT);
8202+
SDValue StepVec = DAG.getStepVector(sdl, IdxVecVT);
8203+
SDValue ActiveElts = DAG.getSelect(sdl, IdxVecVT, Mask, StepVec, Zeroes);
8204+
SDValue HighestIdx =
8205+
DAG.getNode(ISD::VECREDUCE_UMAX, sdl, IdxVT, ActiveElts);
8206+
SDValue Extract =
8207+
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl, ScalarVT, Data, HighestIdx);
8208+
SDValue AnyActive = DAG.getNode(ISD::VECREDUCE_OR, sdl, BoolVT, Mask);
8209+
SDValue Result = DAG.getSelect(sdl, ScalarVT, AnyActive, Extract, PassThru);
8210+
setValue(&I, Result);
8211+
return;
8212+
}
81908213
}
81918214
}
81928215

0 commit comments

Comments
 (0)