Skip to content

Commit b4a9650

Browse files
[SelectionDAG] Add an ISD node for for get.active.lane.mask
For now expansion still happens in SelectionDAGBuilder when GET_ACTIVE_LANE_MASK is not legal on the target. This patch also includes changes in AArch64ISelLowering to replace handling of the get.active.lane.mask intrinsic to use the ISD node. Tablegen patterns are added which match to whilelo for scalable types. A follow up change will add support for more types to be lowered to GET_ACTIVE_LANE_MASK by allowing splitting of the node.
1 parent 18f8928 commit b4a9650

File tree

9 files changed

+165
-105
lines changed

9 files changed

+165
-105
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,12 @@ enum NodeType {
15241524
// Operands: Mask
15251525
VECTOR_FIND_LAST_ACTIVE,
15261526

1527+
// Creates a mask representing active and inactive
1528+
// vector lanes, active while base < trip count.
1529+
// Operands: Base, Trip Count
1530+
// Output: Mask
1531+
GET_ACTIVE_LANE_MASK,
1532+
15271533
// llvm.clear_cache intrinsic
15281534
// Operands: Input Chain, Start Addres, End Address
15291535
// Outputs: Output Chain

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,12 @@ def find_last_active
860860
: SDNode<"ISD::VECTOR_FIND_LAST_ACTIVE",
861861
SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisVec<1>]>, []>;
862862

863+
def get_active_lane_mask
864+
: SDNode<
865+
"ISD::GET_ACTIVE_LANE_MASK",
866+
SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<1, 2>]>,
867+
[]>;
868+
863869
// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
864870
// these internally. Don't reference these directly.
865871
def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N, unsigned ResNo) {
160160
Res = PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(N);
161161
break;
162162

163+
case ISD::GET_ACTIVE_LANE_MASK:
164+
Res = PromoteIntRes_GET_ACTIVE_LANE_MASK(N);
165+
break;
166+
163167
case ISD::PARTIAL_REDUCE_UMLA:
164168
case ISD::PARTIAL_REDUCE_SMLA:
165169
Res = PromoteIntRes_PARTIAL_REDUCE_MLA(N);
@@ -6222,6 +6226,12 @@ SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(SDNode *N) {
62226226
return DAG.getNode(ISD::VECTOR_FIND_LAST_ACTIVE, SDLoc(N), NVT, N->ops());
62236227
}
62246228

6229+
SDValue DAGTypeLegalizer::PromoteIntRes_GET_ACTIVE_LANE_MASK(SDNode *N) {
6230+
EVT VT = N->getValueType(0);
6231+
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6232+
return DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, SDLoc(N), NVT, N->ops());
6233+
}
6234+
62256235
SDValue DAGTypeLegalizer::PromoteIntRes_PARTIAL_REDUCE_MLA(SDNode *N) {
62266236
SDLoc DL(N);
62276237
EVT VT = N->getValueType(0);

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
379379
SDValue PromoteIntRes_IS_FPCLASS(SDNode *N);
380380
SDValue PromoteIntRes_PATCHPOINT(SDNode *N);
381381
SDValue PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(SDNode *N);
382+
SDValue PromoteIntRes_GET_ACTIVE_LANE_MASK(SDNode *N);
382383
SDValue PromoteIntRes_PARTIAL_REDUCE_MLA(SDNode *N);
383384

384385
// Integer Operand Promotion.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7987,14 +7987,15 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
79877987
case Intrinsic::get_active_lane_mask: {
79887988
EVT CCVT = TLI.getValueType(DAG.getDataLayout(), I.getType());
79897989
SDValue Index = getValue(I.getOperand(0));
7990+
SDValue TripCount = getValue(I.getOperand(1));
79907991
EVT ElementVT = Index.getValueType();
79917992

79927993
if (!TLI.shouldExpandGetActiveLaneMask(CCVT, ElementVT)) {
7993-
visitTargetIntrinsic(I, Intrinsic);
7994+
setValue(&I, DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, sdl, CCVT, Index,
7995+
TripCount));
79947996
return;
79957997
}
79967998

7997-
SDValue TripCount = getValue(I.getOperand(1));
79987999
EVT VecTy = EVT::getVectorVT(*DAG.getContext(), ElementVT,
79998000
CCVT.getVectorElementCount());
80008001

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
576576
case ISD::VECTOR_FIND_LAST_ACTIVE:
577577
return "find_last_active";
578578

579+
case ISD::GET_ACTIVE_LANE_MASK:
580+
return "get_active_lane_mask";
581+
579582
case ISD::PARTIAL_REDUCE_UMLA:
580583
return "partial_reduce_umla";
581584
case ISD::PARTIAL_REDUCE_SMLA:

0 commit comments

Comments
 (0)