Skip to content

Commit 3225401

Browse files
[RISCV] Support llvm.masked.compressstore intrinsic
1 parent f448b8e commit 3225401

File tree

4 files changed

+17568
-2
lines changed

4 files changed

+17568
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10461,6 +10461,7 @@ SDValue RISCVTargetLowering::lowerMaskedStore(SDValue Op,
1046110461
SDValue BasePtr = MemSD->getBasePtr();
1046210462
SDValue Val, Mask, VL;
1046310463

10464+
bool IsCompressingStore = false;
1046410465
if (const auto *VPStore = dyn_cast<VPStoreSDNode>(Op)) {
1046510466
Val = VPStore->getValue();
1046610467
Mask = VPStore->getMask();
@@ -10469,9 +10470,11 @@ SDValue RISCVTargetLowering::lowerMaskedStore(SDValue Op,
1046910470
const auto *MStore = cast<MaskedStoreSDNode>(Op);
1047010471
Val = MStore->getValue();
1047110472
Mask = MStore->getMask();
10473+
IsCompressingStore = MStore->isCompressingStore();
1047210474
}
1047310475

10474-
bool IsUnmasked = ISD::isConstantSplatVectorAllOnes(Mask.getNode());
10476+
bool IsUnmasked =
10477+
ISD::isConstantSplatVectorAllOnes(Mask.getNode()) || IsCompressingStore;
1047510478

1047610479
MVT VT = Val.getSimpleValueType();
1047710480
MVT XLenVT = Subtarget.getXLenVT();
@@ -10481,7 +10484,7 @@ SDValue RISCVTargetLowering::lowerMaskedStore(SDValue Op,
1048110484
ContainerVT = getContainerForFixedLengthVector(VT);
1048210485

1048310486
Val = convertToScalableVector(ContainerVT, Val, DAG, Subtarget);
10484-
if (!IsUnmasked) {
10487+
if (!IsUnmasked || IsCompressingStore) {
1048510488
MVT MaskVT = getMaskTypeFor(ContainerVT);
1048610489
Mask = convertToScalableVector(MaskVT, Mask, DAG, Subtarget);
1048710490
}
@@ -10490,6 +10493,15 @@ SDValue RISCVTargetLowering::lowerMaskedStore(SDValue Op,
1049010493
if (!VL)
1049110494
VL = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget).second;
1049210495

10496+
if (IsCompressingStore) {
10497+
Val = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, ContainerVT,
10498+
DAG.getConstant(Intrinsic::riscv_vcompress, DL, XLenVT),
10499+
DAG.getUNDEF(ContainerVT), Val, Mask, VL);
10500+
VL =
10501+
DAG.getNode(RISCVISD::VCPOP_VL, DL, XLenVT, Mask,
10502+
getAllOnesMask(Mask.getSimpleValueType(), VL, DL, DAG), VL);
10503+
}
10504+
1049310505
unsigned IntID =
1049410506
IsUnmasked ? Intrinsic::riscv_vse : Intrinsic::riscv_vse_mask;
1049510507
SmallVector<SDValue, 8> Ops{Chain, DAG.getTargetConstant(IntID, DL, XLenVT)};

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,3 +1620,10 @@ bool RISCVTTIImpl::isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
16201620
C2.NumIVMuls, C2.NumBaseAdds,
16211621
C2.ScaleCost, C2.ImmCost, C2.SetupCost);
16221622
}
1623+
1624+
bool RISCVTTIImpl::isLegalMaskedCompressStore(Type *DataTy) {
1625+
auto *VTy = dyn_cast<VectorType>(DataTy);
1626+
if (!VTy || VTy->isScalableTy() || !ST->hasVInstructions())
1627+
return false;
1628+
return getRegUsageForType(VTy) <= 8;
1629+
}

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
261261
return TLI->isLegalStridedLoadStore(DataTypeVT, Alignment);
262262
}
263263

264+
bool isLegalMaskedCompressStore(Type *DataTy);
265+
264266
bool isVScaleKnownToBeAPowerOfTwo() const {
265267
return TLI->isVScaleKnownToBeAPowerOfTwo();
266268
}

0 commit comments

Comments
 (0)