Skip to content

Commit 0bc3993

Browse files
[SelectionDAG] Add an ISD node for for get.active.lane.mask (#139084)
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 780054d commit 0bc3993

File tree

9 files changed

+158
-110
lines changed

9 files changed

+158
-110
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,15 @@ enum NodeType {
15331533
// Operands: Mask
15341534
VECTOR_FIND_LAST_ACTIVE,
15351535

1536+
// GET_ACTIVE_LANE_MASK - this corrosponds to the llvm.get.active.lane.mask
1537+
// intrinsic. It creates a mask representing active and inactive vector
1538+
// lanes, active while Base + index < Trip Count. As with the intrinsic,
1539+
// the operands Base and Trip Count have the same scalar integer type and
1540+
// the internal addition of Base + index cannot overflow. However, the ISD
1541+
// node supports result types which are wider than i1, where the high
1542+
// bits conform to getBooleanContents similar to the SETCC operator.
1543+
GET_ACTIVE_LANE_MASK,
1544+
15361545
// llvm.clear_cache intrinsic
15371546
// Operands: Input Chain, Start Addres, End Address
15381547
// 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
@@ -577,6 +577,9 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
577577
case ISD::VECTOR_FIND_LAST_ACTIVE:
578578
return "find_last_active";
579579

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

0 commit comments

Comments
 (0)