Skip to content

Commit 86fa3e3

Browse files
committed
[RISCV] Lower mgather/mscatter for zvfhmin/zvfbfmin
In preparation for allowing zvfhmin and zvfbfmin in isLegalElementTypeForRVV, this lowers masked gathers and scatters. We need to mark f16 and bf16 as legal in isLegalMaskedGatherScatter otherwise ScalarizeMaskedMemIntrin will just scalarize them, but we can move this back into isLegalElementTypeForRVV afterwards. The scalarized codegen required llvm#114938, llvm#114927 and llvm#114915 to not crash.
1 parent fde526c commit 86fa3e3

File tree

4 files changed

+386
-7625
lines changed

4 files changed

+386
-7625
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,9 +1339,10 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
13391339
ISD::VECTOR_SHUFFLE, ISD::VECTOR_COMPRESS},
13401340
VT, Custom);
13411341

1342-
// FIXME: mload, mstore, mgather, mscatter, vp_gather/scatter can be
1342+
// FIXME: mload, mstore, vp_gather/scatter can be
13431343
// hoisted to here.
1344-
setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom);
1344+
setOperationAction({ISD::LOAD, ISD::STORE, ISD::MGATHER, ISD::MSCATTER},
1345+
VT, Custom);
13451346
setOperationAction({ISD::VP_LOAD, ISD::VP_STORE,
13461347
ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
13471348
ISD::EXPERIMENTAL_VP_STRIDED_STORE},
@@ -1408,8 +1409,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14081409
setOperationAction({ISD::BUILD_VECTOR, ISD::SCALAR_TO_VECTOR}, VT,
14091410
Custom);
14101411

1411-
setOperationAction(
1412-
{ISD::MLOAD, ISD::MSTORE, ISD::MGATHER, ISD::MSCATTER}, VT, Custom);
1412+
setOperationAction({ISD::MLOAD, ISD::MSTORE}, VT, Custom);
14131413

14141414
setOperationAction({ISD::VP_GATHER, ISD::VP_SCATTER}, VT, Custom);
14151415

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,12 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
270270
if (!ST->enableUnalignedVectorMem() && Alignment < ElemType.getStoreSize())
271271
return false;
272272

273-
return TLI->isLegalElementTypeForRVV(ElemType);
273+
// TODO: Move bf16/f16 support into isLegalElementTypeForRVV
274+
return TLI->isLegalElementTypeForRVV(ElemType) ||
275+
(DataTypeVT.getVectorElementType() == MVT::bf16 &&
276+
ST->hasVInstructionsBF16Minimal()) ||
277+
(DataTypeVT.getVectorElementType() == MVT::f16 &&
278+
ST->hasVInstructionsF16Minimal());
274279
}
275280

276281
bool isLegalMaskedGather(Type *DataType, Align Alignment) {

0 commit comments

Comments
 (0)