Skip to content

Commit 8cf43ae

Browse files
[LLVM][CodeGen][SVE] Remove failure cases when widening vector load/store ops. (#160515)
When unable to widen a vector load/store we can replace the operation with a masked variant. Support for extending loads largely came for free hence its inclusion, but truncating stores require more work. Fixes #159995
1 parent f3f9e7b commit 8cf43ae

File tree

5 files changed

+2923
-40
lines changed

5 files changed

+2923
-40
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6256,17 +6256,17 @@ SDValue DAGTypeLegalizer::WidenVecRes_LOAD(SDNode *N) {
62566256
// FIXME: Not all targets may support EVL in VP_LOAD. These will have been
62576257
// removed from the IR by the ExpandVectorPredication pass but we're
62586258
// reintroducing them here.
6259-
EVT LdVT = LD->getMemoryVT();
6260-
EVT WideVT = TLI.getTypeToTransformTo(*DAG.getContext(), LdVT);
6261-
EVT WideMaskVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1,
6262-
WideVT.getVectorElementCount());
6259+
EVT VT = LD->getValueType(0);
6260+
EVT WideVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6261+
EVT WideMaskVT = getSetCCResultType(WideVT);
6262+
62636263
if (ExtType == ISD::NON_EXTLOAD &&
62646264
TLI.isOperationLegalOrCustom(ISD::VP_LOAD, WideVT) &&
62656265
TLI.isTypeLegal(WideMaskVT)) {
62666266
SDLoc DL(N);
62676267
SDValue Mask = DAG.getAllOnesConstant(DL, WideMaskVT);
62686268
SDValue EVL = DAG.getElementCount(DL, TLI.getVPExplicitVectorLengthTy(),
6269-
LdVT.getVectorElementCount());
6269+
VT.getVectorElementCount());
62706270
SDValue NewLoad =
62716271
DAG.getLoadVP(LD->getAddressingMode(), ISD::NON_EXTLOAD, WideVT, DL,
62726272
LD->getChain(), LD->getBasePtr(), LD->getOffset(), Mask,
@@ -6303,6 +6303,24 @@ SDValue DAGTypeLegalizer::WidenVecRes_LOAD(SDNode *N) {
63036303
return Result;
63046304
}
63056305

6306+
if (VT.isVector()) {
6307+
// If all else fails replace the load with a wide masked load.
6308+
SDLoc DL(N);
6309+
EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
6310+
6311+
SDValue Len = DAG.getElementCount(DL, IdxVT, VT.getVectorElementCount());
6312+
SDValue Mask = DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, DL, WideMaskVT,
6313+
DAG.getConstant(0, DL, IdxVT), Len);
6314+
6315+
SDValue NewLoad = DAG.getMaskedLoad(
6316+
WideVT, DL, LD->getChain(), LD->getBasePtr(), LD->getOffset(), Mask,
6317+
DAG.getPOISON(WideVT), LD->getMemoryVT(), LD->getMemOperand(),
6318+
LD->getAddressingMode(), LD->getExtensionType());
6319+
6320+
ReplaceValueWith(SDValue(N, 1), NewLoad.getValue(1));
6321+
return NewLoad;
6322+
}
6323+
63066324
report_fatal_error("Unable to widen vector load");
63076325
}
63086326

@@ -7516,8 +7534,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_STORE(SDNode *N) {
75167534
SDValue StVal = ST->getValue();
75177535
EVT StVT = StVal.getValueType();
75187536
EVT WideVT = TLI.getTypeToTransformTo(*DAG.getContext(), StVT);
7519-
EVT WideMaskVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1,
7520-
WideVT.getVectorElementCount());
7537+
EVT WideMaskVT = getSetCCResultType(WideVT);
75217538

75227539
if (TLI.isOperationLegalOrCustom(ISD::VP_STORE, WideVT) &&
75237540
TLI.isTypeLegal(WideMaskVT)) {
@@ -7540,6 +7557,22 @@ SDValue DAGTypeLegalizer::WidenVecOp_STORE(SDNode *N) {
75407557
return DAG.getNode(ISD::TokenFactor, SDLoc(ST), MVT::Other, StChain);
75417558
}
75427559

7560+
if (StVT.isVector()) {
7561+
// If all else fails replace the store with a wide masked store.
7562+
SDLoc DL(N);
7563+
EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
7564+
7565+
SDValue WideStVal = GetWidenedVector(StVal);
7566+
SDValue Len = DAG.getElementCount(DL, IdxVT, StVT.getVectorElementCount());
7567+
SDValue Mask = DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, DL, WideMaskVT,
7568+
DAG.getConstant(0, DL, IdxVT), Len);
7569+
7570+
return DAG.getMaskedStore(ST->getChain(), DL, WideStVal, ST->getBasePtr(),
7571+
ST->getOffset(), Mask, ST->getMemoryVT(),
7572+
ST->getMemOperand(), ST->getAddressingMode(),
7573+
ST->isTruncatingStore());
7574+
}
7575+
75437576
report_fatal_error("Unable to widen vector store");
75447577
}
75457578

@@ -8298,8 +8331,7 @@ DAGTypeLegalizer::GenWidenVectorExtLoads(SmallVectorImpl<SDValue> &LdChain,
82988331
AAMDNodes AAInfo = LD->getAAInfo();
82998332

83008333
if (LdVT.isScalableVector())
8301-
report_fatal_error("Generating widen scalable extending vector loads is "
8302-
"not yet supported");
8334+
return SDValue();
83038335

83048336
EVT EltVT = WidenVT.getVectorElementType();
83058337
EVT LdEltVT = LdVT.getVectorElementType();

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
15371537
setOperationAction(ISD::FP_TO_UINT, VT, Custom);
15381538
setOperationAction(ISD::FP_TO_SINT, VT, Custom);
15391539
setOperationAction(ISD::MLOAD, VT, Custom);
1540+
setOperationAction(ISD::MSTORE, VT, Legal);
15401541
setOperationAction(ISD::MUL, VT, Custom);
15411542
setOperationAction(ISD::MULHS, VT, Custom);
15421543
setOperationAction(ISD::MULHU, VT, Custom);

llvm/lib/Target/VE/VEISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,8 @@ const char *VETargetLowering::getTargetNodeName(unsigned Opcode) const {
957957

958958
EVT VETargetLowering::getSetCCResultType(const DataLayout &, LLVMContext &,
959959
EVT VT) const {
960+
if (VT.isVector())
961+
return VT.changeVectorElementType(MVT::i1);
960962
return MVT::i32;
961963
}
962964

0 commit comments

Comments
 (0)