diff options
author | Paul Walker <paul.walker@arm.com> | 2024-05-01 11:10:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 11:10:47 +0100 |
commit | fdf206c10ccea9dd5bd3d7eeb1381f305f972e52 (patch) | |
tree | 8cd0d936b4e97533352efaa4ffbe75eab79fa22a /llvm/lib | |
parent | 9bebf25ecbe6a8720dd581bd2a4f8d29aa763a42 (diff) | |
download | llvm-fdf206c10ccea9dd5bd3d7eeb1381f305f972e52.zip llvm-fdf206c10ccea9dd5bd3d7eeb1381f305f972e52.tar.gz llvm-fdf206c10ccea9dd5bd3d7eeb1381f305f972e52.tar.bz2 |
[LLVM][SVE] Improve legalisation of fixed length get.active.lane.mask (#90213)
We are effectively performing type and operation legalisation very early
within the code generation flow. This results in worse code quality
because the DAG is not in canonical form, which DAGCombiner corrects
through the introduction of operations that are not legal.
This patchs splits and moves the code to where type and operation
legalisation is typically implemented.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index cb7930f..2af679e 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -1677,6 +1677,9 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM, setOperationPromotedToType(ISD::VECTOR_SPLICE, MVT::nxv16i1, MVT::nxv16i8); setOperationAction(ISD::VSCALE, MVT::i32, Custom); + + for (auto VT : {MVT::v16i1, MVT::v8i1, MVT::v4i1, MVT::v2i1}) + setOperationAction(ISD::INTRINSIC_WO_CHAIN, VT, Custom); } if (Subtarget->hasMOPS() && Subtarget->hasMTE()) { @@ -5748,8 +5751,24 @@ SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, case Intrinsic::get_active_lane_mask: { SDValue ID = DAG.getTargetConstant(Intrinsic::aarch64_sve_whilelo, dl, MVT::i64); - return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, Op.getValueType(), ID, - Op.getOperand(1), Op.getOperand(2)); + + EVT VT = Op.getValueType(); + if (VT.isScalableVector()) + return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, ID, Op.getOperand(1), + Op.getOperand(2)); + + // We can use the SVE whilelo instruction to lower this intrinsic by + // creating the appropriate sequence of scalable vector operations and + // then extracting a fixed-width subvector from the scalable vector. + + EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT); + EVT WhileVT = ContainerVT.changeElementType(MVT::i1); + + SDValue Mask = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, WhileVT, ID, + Op.getOperand(1), Op.getOperand(2)); + SDValue MaskAsInt = DAG.getNode(ISD::SIGN_EXTEND, dl, ContainerVT, Mask); + return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, MaskAsInt, + DAG.getVectorIdxConstant(0, dl)); } case Intrinsic::aarch64_neon_uaddlv: { EVT OpVT = Op.getOperand(1).getValueType(); @@ -20530,39 +20549,6 @@ static SDValue performIntrinsicCombine(SDNode *N, switch (IID) { default: break; - case Intrinsic::get_active_lane_mask: { - SDValue Res = SDValue(); - EVT VT = N->getValueType(0); - if (VT.isFixedLengthVector()) { - // We can use the SVE whilelo instruction to lower this intrinsic by - // creating the appropriate sequence of scalable vector operations and - // then extracting a fixed-width subvector from the scalable vector. - - SDLoc DL(N); - SDValue ID = - DAG.getTargetConstant(Intrinsic::aarch64_sve_whilelo, DL, MVT::i64); - - EVT WhileVT = EVT::getVectorVT( - *DAG.getContext(), MVT::i1, - ElementCount::getScalable(VT.getVectorNumElements())); - - // Get promoted scalable vector VT, i.e. promote nxv4i1 -> nxv4i32. - EVT PromVT = getPromotedVTForPredicate(WhileVT); - - // Get the fixed-width equivalent of PromVT for extraction. - EVT ExtVT = - EVT::getVectorVT(*DAG.getContext(), PromVT.getVectorElementType(), - VT.getVectorElementCount()); - - Res = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, WhileVT, ID, - N->getOperand(1), N->getOperand(2)); - Res = DAG.getNode(ISD::SIGN_EXTEND, DL, PromVT, Res); - Res = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ExtVT, Res, - DAG.getConstant(0, DL, MVT::i64)); - Res = DAG.getNode(ISD::TRUNCATE, DL, VT, Res); - } - return Res; - } case Intrinsic::aarch64_neon_vcvtfxs2fp: case Intrinsic::aarch64_neon_vcvtfxu2fp: return tryCombineFixedPointConvert(N, DCI, DAG); @@ -25636,8 +25622,6 @@ void AArch64TargetLowering::ReplaceNodeResults( return; case ISD::INTRINSIC_WO_CHAIN: { EVT VT = N->getValueType(0); - assert((VT == MVT::i8 || VT == MVT::i16) && - "custom lowering for unexpected type"); Intrinsic::ID IntID = static_cast<Intrinsic::ID>(N->getConstantOperandVal(0)); @@ -25645,6 +25629,8 @@ void AArch64TargetLowering::ReplaceNodeResults( default: return; case Intrinsic::aarch64_sve_clasta_n: { + assert((VT == MVT::i8 || VT == MVT::i16) && + "custom lowering for unexpected type"); SDLoc DL(N); auto Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, N->getOperand(2)); auto V = DAG.getNode(AArch64ISD::CLASTA_N, DL, MVT::i32, @@ -25653,6 +25639,8 @@ void AArch64TargetLowering::ReplaceNodeResults( return; } case Intrinsic::aarch64_sve_clastb_n: { + assert((VT == MVT::i8 || VT == MVT::i16) && + "custom lowering for unexpected type"); SDLoc DL(N); auto Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, N->getOperand(2)); auto V = DAG.getNode(AArch64ISD::CLASTB_N, DL, MVT::i32, @@ -25661,6 +25649,8 @@ void AArch64TargetLowering::ReplaceNodeResults( return; } case Intrinsic::aarch64_sve_lasta: { + assert((VT == MVT::i8 || VT == MVT::i16) && + "custom lowering for unexpected type"); SDLoc DL(N); auto V = DAG.getNode(AArch64ISD::LASTA, DL, MVT::i32, N->getOperand(1), N->getOperand(2)); @@ -25668,12 +25658,28 @@ void AArch64TargetLowering::ReplaceNodeResults( return; } case Intrinsic::aarch64_sve_lastb: { + assert((VT == MVT::i8 || VT == MVT::i16) && + "custom lowering for unexpected type"); SDLoc DL(N); auto V = DAG.getNode(AArch64ISD::LASTB, DL, MVT::i32, N->getOperand(1), N->getOperand(2)); Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V)); return; } + case Intrinsic::get_active_lane_mask: { + if (!VT.isFixedLengthVector() || VT.getVectorElementType() != MVT::i1) + return; + + // NOTE: Only trivial type promotion is supported. + EVT NewVT = getTypeToTransformTo(*DAG.getContext(), VT); + if (NewVT.getVectorNumElements() != VT.getVectorNumElements()) + return; + + SDLoc DL(N); + auto V = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, NewVT, N->ops()); + Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V)); + return; + } } } case ISD::READ_REGISTER: { |