Skip to content

Commit e4d20fb

Browse files
committed
Initial working version via scalarization
1 parent 7c04da1 commit e4d20fb

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
@@ -20002,6 +20002,36 @@ the follow sequence of operations:
2000220002

2000320003
The ``mask`` operand will apply to at least the gather and scatter operations.
2000420004

20005+
'``llvm.experimental.vector.masked.extract.last.active``' Intrinsic
20006+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20007+
20008+
This is an overloaded intrinsic.
20009+
20010+
This intrinsic will extract the value from a single lane of a vector, based
20011+
on a supplied mask vector.
20012+
20013+
::
20014+
20015+
declare i32 @llvm.experimental.vector.masked.extract.last.active.v4i32(<4 x i32> %data, <4 x i1> %mask, i32 %passthru)
20016+
declare i16 @llvm.experimental.vector.masked.extract.last.active.nxv8i16(<vscale x 8 x i16> %data, <vscale x 8 x i1> %mask, i16 %passthru)
20017+
20018+
Arguments:
20019+
""""""""""
20020+
20021+
The first argument is the data vector to extract a lane from. The second is a
20022+
mask vector controlling the extraction. The third argument is a passthru
20023+
value.
20024+
20025+
The two input vectors must have the same number of elements, and the type of
20026+
the passthru value must match that of the elements of the data vector.
20027+
20028+
Semantics:
20029+
""""""""""
20030+
20031+
The '``llvm.experimental.vector.masked.extract.last.active``' intrinsic will
20032+
find the index of the most significant active lane in the mask vector, and
20033+
extract the element at that index in the corresponding data vector. If no mask
20034+
lanes are active then the passthru value is returned instead.
2000520035

2000620036
.. _int_vector_compress:
2000720037

llvm/include/llvm/IR/Intrinsics.td

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

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

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8207,6 +8207,29 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
82078207
visitVectorHistogram(I, Intrinsic);
82088208
return;
82098209
}
8210+
case Intrinsic::experimental_vector_masked_extract_last_active: {
8211+
SDValue Data = getValue(I.getOperand(0));
8212+
SDValue Mask = getValue(I.getOperand(1));
8213+
SDValue PassThru = getValue(I.getOperand(2));
8214+
8215+
EVT DataVT = Data.getValueType();
8216+
EVT ScalarVT = PassThru.getValueType();
8217+
EVT BoolVT = Mask.getValueType().getScalarType();
8218+
EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
8219+
EVT IdxVecVT = DataVT.changeVectorElementType(IdxVT);
8220+
8221+
SDValue Zeroes = DAG.getConstant(0, sdl, IdxVecVT);
8222+
SDValue StepVec = DAG.getStepVector(sdl, IdxVecVT);
8223+
SDValue ActiveElts = DAG.getSelect(sdl, IdxVecVT, Mask, StepVec, Zeroes);
8224+
SDValue HighestIdx =
8225+
DAG.getNode(ISD::VECREDUCE_UMAX, sdl, IdxVT, ActiveElts);
8226+
SDValue Extract =
8227+
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl, ScalarVT, Data, HighestIdx);
8228+
SDValue AnyActive = DAG.getNode(ISD::VECREDUCE_OR, sdl, BoolVT, Mask);
8229+
SDValue Result = DAG.getSelect(sdl, ScalarVT, AnyActive, Extract, PassThru);
8230+
setValue(&I, Result);
8231+
return;
8232+
}
82108233
}
82118234
}
82128235

0 commit comments

Comments
 (0)