[llvm] [AArch64] Lower masked.expandload intrinsic using SVE2p2/SME2p2 EXPAND (PR #190999)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 05:21:49 PDT 2026
================
@@ -7436,16 +7365,52 @@ SDValue AArch64TargetLowering::LowerMLOAD(SDValue Op, SelectionDAG &DAG) const {
SDValue PassThru = LoadNode->getPassThru();
SDValue Mask = LoadNode->getMask();
- if (PassThru->isUndef() || isZerosVector(PassThru.getNode()))
+ if (!LoadNode->isExpandingLoad()) {
+ if (PassThru->isUndef() || isZerosVector(PassThru.getNode()))
+ return Op;
+
+ SDValue Load = DAG.getMaskedLoad(
+ VT, DL, LoadNode->getChain(), LoadNode->getBasePtr(),
+ LoadNode->getOffset(), Mask, DAG.getUNDEF(VT), LoadNode->getMemoryVT(),
+ LoadNode->getMemOperand(), LoadNode->getAddressingMode(),
+ LoadNode->getExtensionType());
+
+ SDValue Result = DAG.getSelect(DL, VT, Mask, Load, PassThru);
+ return DAG.getMergeValues({Result, Load.getValue(1)}, DL);
+ }
+
+ // Return if EXPAND instruction is not available.
+ if ((!Subtarget->isSVEAvailable() || !Subtarget->hasSVE2p2()) &&
+ (!Subtarget->isSVEorStreamingSVEAvailable() || !Subtarget->hasSME2p2()))
return Op;
+ // Create mask using the number of active lanes in the predicate.
+ SDValue CntActive = DAG.getNode(
+ ISD::INTRINSIC_WO_CHAIN, DL, MVT::i64,
+ DAG.getTargetConstant(Intrinsic::aarch64_sve_cntp, DL, MVT::i64), Mask,
+ Mask);
+
+ SDValue ActiveMask =
+ DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, DL, Mask->getValueType(0),
+ DAG.getConstant(0, DL, MVT::i64), CntActive);
+
+ // Contiguous load of elements using the active lane mask above.
SDValue Load = DAG.getMaskedLoad(
VT, DL, LoadNode->getChain(), LoadNode->getBasePtr(),
- LoadNode->getOffset(), Mask, DAG.getUNDEF(VT), LoadNode->getMemoryVT(),
- LoadNode->getMemOperand(), LoadNode->getAddressingMode(),
- LoadNode->getExtensionType());
+ LoadNode->getOffset(), ActiveMask, DAG.getUNDEF(VT),
+ LoadNode->getMemoryVT(), LoadNode->getMemOperand(),
+ LoadNode->getAddressingMode(), LoadNode->getExtensionType());
+
+ // Expand instruction copies the low-numbered elements to active elements
+ // in the original predicate.
----------------
paulwalker-arm wrote:
Perhaps worth adding "and zeros all other lanes"? to make it clear why the following isZerosVector check is valid.
https://github.com/llvm/llvm-project/pull/190999
More information about the llvm-commits
mailing list