-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[RISCV] Removeriscv.segN.load/store
in favor of their mask variants
#137045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mshockwave
merged 3 commits into
llvm:main
from
mshockwave:patch/riscv/remove-unmasked-segX
May 8, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1745,13 +1745,6 @@ bool RISCVTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, | |
Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore | | ||
MachineMemOperand::MOVolatile; | ||
return true; | ||
case Intrinsic::riscv_seg2_load: | ||
case Intrinsic::riscv_seg3_load: | ||
case Intrinsic::riscv_seg4_load: | ||
case Intrinsic::riscv_seg5_load: | ||
case Intrinsic::riscv_seg6_load: | ||
case Intrinsic::riscv_seg7_load: | ||
case Intrinsic::riscv_seg8_load: | ||
case Intrinsic::riscv_seg2_load_mask: | ||
case Intrinsic::riscv_seg3_load_mask: | ||
case Intrinsic::riscv_seg4_load_mask: | ||
|
@@ -1761,17 +1754,6 @@ bool RISCVTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, | |
case Intrinsic::riscv_seg8_load_mask: | ||
return SetRVVLoadStoreInfo(/*PtrOp*/ 0, /*IsStore*/ false, | ||
/*IsUnitStrided*/ false, /*UsePtrVal*/ true); | ||
case Intrinsic::riscv_seg2_store: | ||
case Intrinsic::riscv_seg3_store: | ||
case Intrinsic::riscv_seg4_store: | ||
case Intrinsic::riscv_seg5_store: | ||
case Intrinsic::riscv_seg6_store: | ||
case Intrinsic::riscv_seg7_store: | ||
case Intrinsic::riscv_seg8_store: | ||
// Operands are (vec, ..., vec, ptr, vl) | ||
return SetRVVLoadStoreInfo(/*PtrOp*/ I.arg_size() - 2, | ||
/*IsStore*/ true, | ||
/*IsUnitStrided*/ false, /*UsePtrVal*/ true); | ||
case Intrinsic::riscv_seg2_store_mask: | ||
case Intrinsic::riscv_seg3_store_mask: | ||
case Intrinsic::riscv_seg4_store_mask: | ||
|
@@ -10591,13 +10573,6 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op, | |
switch (IntNo) { | ||
default: | ||
break; | ||
case Intrinsic::riscv_seg2_load: | ||
case Intrinsic::riscv_seg3_load: | ||
case Intrinsic::riscv_seg4_load: | ||
case Intrinsic::riscv_seg5_load: | ||
case Intrinsic::riscv_seg6_load: | ||
case Intrinsic::riscv_seg7_load: | ||
case Intrinsic::riscv_seg8_load: | ||
case Intrinsic::riscv_seg2_load_mask: | ||
case Intrinsic::riscv_seg3_load_mask: | ||
case Intrinsic::riscv_seg4_load_mask: | ||
|
@@ -10620,18 +10595,13 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op, | |
ContainerVT.getScalarSizeInBits(); | ||
EVT VecTupTy = MVT::getRISCVVectorTupleVT(Sz, NF); | ||
|
||
// Masked: (pointer, mask, vl) | ||
// Non-masked: (pointer, vl) | ||
bool IsMasked = Op.getNumOperands() > 4; | ||
// Operands: (chain, int_id, pointer, mask, vl) | ||
SDValue VL = Op.getOperand(Op.getNumOperands() - 1); | ||
SDValue Mask = | ||
IsMasked ? Op.getOperand(3) : getAllOnesMask(ContainerVT, VL, DL, DAG); | ||
SDValue Mask = Op.getOperand(3); | ||
MVT MaskVT = Mask.getSimpleValueType(); | ||
if (MaskVT.isFixedLengthVector()) { | ||
MVT MaskContainerVT = | ||
::getContainerForFixedLengthVector(DAG, MaskVT, Subtarget); | ||
Mask = convertToScalableVector(MaskContainerVT, Mask, DAG, Subtarget); | ||
} | ||
MVT MaskContainerVT = | ||
::getContainerForFixedLengthVector(DAG, MaskVT, Subtarget); | ||
Mask = convertToScalableVector(MaskContainerVT, Mask, DAG, Subtarget); | ||
|
||
SDValue IntID = DAG.getTargetConstant(VlsegInts[NF - 2], DL, XLenVT); | ||
auto *Load = cast<MemIntrinsicSDNode>(Op); | ||
|
@@ -10699,13 +10669,6 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_VOID(SDValue Op, | |
switch (IntNo) { | ||
default: | ||
break; | ||
case Intrinsic::riscv_seg2_store: | ||
case Intrinsic::riscv_seg3_store: | ||
case Intrinsic::riscv_seg4_store: | ||
case Intrinsic::riscv_seg5_store: | ||
case Intrinsic::riscv_seg6_store: | ||
case Intrinsic::riscv_seg7_store: | ||
case Intrinsic::riscv_seg8_store: | ||
case Intrinsic::riscv_seg2_store_mask: | ||
case Intrinsic::riscv_seg3_store_mask: | ||
case Intrinsic::riscv_seg4_store_mask: | ||
|
@@ -10720,24 +10683,8 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_VOID(SDValue Op, | |
Intrinsic::riscv_vsseg6_mask, Intrinsic::riscv_vsseg7_mask, | ||
Intrinsic::riscv_vsseg8_mask}; | ||
|
||
bool IsMasked = false; | ||
switch (IntNo) { | ||
case Intrinsic::riscv_seg2_store_mask: | ||
case Intrinsic::riscv_seg3_store_mask: | ||
case Intrinsic::riscv_seg4_store_mask: | ||
case Intrinsic::riscv_seg5_store_mask: | ||
case Intrinsic::riscv_seg6_store_mask: | ||
case Intrinsic::riscv_seg7_store_mask: | ||
case Intrinsic::riscv_seg8_store_mask: | ||
IsMasked = true; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
// Non-masked: (chain, int_id, vec*, ptr, vl) | ||
// Masked: (chain, int_id, vec*, ptr, mask, vl) | ||
unsigned NF = Op->getNumOperands() - (IsMasked ? 5 : 4); | ||
// Operands: (chain, int_id, vec*, ptr, mask, vl) | ||
unsigned NF = Op->getNumOperands() - 5; | ||
assert(NF >= 2 && NF <= 8 && "Unexpected seg number"); | ||
MVT XLenVT = Subtarget.getXLenVT(); | ||
MVT VT = Op->getOperand(2).getSimpleValueType(); | ||
|
@@ -10747,14 +10694,11 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_VOID(SDValue Op, | |
EVT VecTupTy = MVT::getRISCVVectorTupleVT(Sz, NF); | ||
|
||
SDValue VL = Op.getOperand(Op.getNumOperands() - 1); | ||
SDValue Mask = IsMasked ? Op.getOperand(Op.getNumOperands() - 2) | ||
: getAllOnesMask(ContainerVT, VL, DL, DAG); | ||
SDValue Mask = Op.getOperand(Op.getNumOperands() - 2); | ||
MVT MaskVT = Mask.getSimpleValueType(); | ||
if (MaskVT.isFixedLengthVector()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, remove the check here |
||
MVT MaskContainerVT = | ||
::getContainerForFixedLengthVector(DAG, MaskVT, Subtarget); | ||
Mask = convertToScalableVector(MaskContainerVT, Mask, DAG, Subtarget); | ||
} | ||
MVT MaskContainerVT = | ||
::getContainerForFixedLengthVector(DAG, MaskVT, Subtarget); | ||
Mask = convertToScalableVector(MaskContainerVT, Mask, DAG, Subtarget); | ||
|
||
SDValue IntID = DAG.getTargetConstant(VssegInts[NF - 2], DL, XLenVT); | ||
SDValue Ptr = Op->getOperand(NF + 2); | ||
|
@@ -23823,10 +23767,10 @@ bool RISCVTargetLowering::isLegalStridedLoadStore(EVT DataType, | |
} | ||
|
||
static const Intrinsic::ID FixedVlsegIntrIds[] = { | ||
Intrinsic::riscv_seg2_load, Intrinsic::riscv_seg3_load, | ||
Intrinsic::riscv_seg4_load, Intrinsic::riscv_seg5_load, | ||
Intrinsic::riscv_seg6_load, Intrinsic::riscv_seg7_load, | ||
Intrinsic::riscv_seg8_load}; | ||
Intrinsic::riscv_seg2_load_mask, Intrinsic::riscv_seg3_load_mask, | ||
Intrinsic::riscv_seg4_load_mask, Intrinsic::riscv_seg5_load_mask, | ||
Intrinsic::riscv_seg6_load_mask, Intrinsic::riscv_seg7_load_mask, | ||
Intrinsic::riscv_seg8_load_mask}; | ||
|
||
/// Lower an interleaved load into a vlsegN intrinsic. | ||
/// | ||
|
@@ -23877,10 +23821,10 @@ bool RISCVTargetLowering::lowerInterleavedLoad( | |
}; | ||
|
||
Value *VL = ConstantInt::get(XLenTy, VTy->getNumElements()); | ||
|
||
CallInst *VlsegN = Builder.CreateIntrinsic( | ||
FixedVlsegIntrIds[Factor - 2], {VTy, LI->getPointerOperandType(), XLenTy}, | ||
{LI->getPointerOperand(), VL}); | ||
Value *Mask = Builder.getAllOnesMask(VTy->getElementCount()); | ||
CallInst *VlsegN = | ||
Builder.CreateIntrinsic(FixedVlsegIntrIds[Factor - 2], {VTy, XLenTy}, | ||
{LI->getPointerOperand(), Mask, VL}); | ||
|
||
for (unsigned i = 0; i < Shuffles.size(); i++) { | ||
Value *SubVec = Builder.CreateExtractValue(VlsegN, Indices[i]); | ||
|
@@ -23891,10 +23835,10 @@ bool RISCVTargetLowering::lowerInterleavedLoad( | |
} | ||
|
||
static const Intrinsic::ID FixedVssegIntrIds[] = { | ||
Intrinsic::riscv_seg2_store, Intrinsic::riscv_seg3_store, | ||
Intrinsic::riscv_seg4_store, Intrinsic::riscv_seg5_store, | ||
Intrinsic::riscv_seg6_store, Intrinsic::riscv_seg7_store, | ||
Intrinsic::riscv_seg8_store}; | ||
Intrinsic::riscv_seg2_store_mask, Intrinsic::riscv_seg3_store_mask, | ||
Intrinsic::riscv_seg4_store_mask, Intrinsic::riscv_seg5_store_mask, | ||
Intrinsic::riscv_seg6_store_mask, Intrinsic::riscv_seg7_store_mask, | ||
Intrinsic::riscv_seg8_store_mask}; | ||
|
||
/// Lower an interleaved store into a vssegN intrinsic. | ||
/// | ||
|
@@ -23954,8 +23898,7 @@ bool RISCVTargetLowering::lowerInterleavedStore(StoreInst *SI, | |
} | ||
|
||
Function *VssegNFunc = Intrinsic::getOrInsertDeclaration( | ||
SI->getModule(), FixedVssegIntrIds[Factor - 2], | ||
{VTy, SI->getPointerOperandType(), XLenTy}); | ||
SI->getModule(), FixedVssegIntrIds[Factor - 2], {VTy, XLenTy}); | ||
|
||
SmallVector<Value *, 10> Ops; | ||
SmallVector<int, 16> NewShuffleMask; | ||
|
@@ -23975,7 +23918,8 @@ bool RISCVTargetLowering::lowerInterleavedStore(StoreInst *SI, | |
// potentially under larger LMULs) because we checked that the fixed vector | ||
// type fits in isLegalInterleavedAccessType | ||
Value *VL = ConstantInt::get(XLenTy, VTy->getNumElements()); | ||
Ops.append({SI->getPointerOperand(), VL}); | ||
Value *StoreMask = Builder.getAllOnesMask(VTy->getElementCount()); | ||
Ops.append({SI->getPointerOperand(), StoreMask, VL}); | ||
|
||
Builder.CreateCall(VssegNFunc, Ops); | ||
|
||
|
@@ -24004,10 +23948,10 @@ bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToLoad( | |
|
||
if (auto *FVTy = dyn_cast<FixedVectorType>(ResVTy)) { | ||
Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements()); | ||
Value *Mask = Builder.getAllOnesMask(FVTy->getElementCount()); | ||
Return = | ||
Builder.CreateIntrinsic(FixedVlsegIntrIds[Factor - 2], | ||
{ResVTy, LI->getPointerOperandType(), XLenTy}, | ||
{LI->getPointerOperand(), VL}); | ||
Builder.CreateIntrinsic(FixedVlsegIntrIds[Factor - 2], {ResVTy, XLenTy}, | ||
{LI->getPointerOperand(), Mask, VL}); | ||
} else { | ||
static const Intrinsic::ID IntrIds[] = { | ||
Intrinsic::riscv_vlseg2, Intrinsic::riscv_vlseg3, | ||
|
@@ -24071,12 +24015,12 @@ bool RISCVTargetLowering::lowerInterleaveIntrinsicToStore( | |
|
||
if (auto *FVTy = dyn_cast<FixedVectorType>(InVTy)) { | ||
Function *VssegNFunc = Intrinsic::getOrInsertDeclaration( | ||
SI->getModule(), FixedVssegIntrIds[Factor - 2], | ||
{InVTy, SI->getPointerOperandType(), XLenTy}); | ||
SI->getModule(), FixedVssegIntrIds[Factor - 2], {InVTy, XLenTy}); | ||
|
||
SmallVector<Value *, 10> Ops(InterleaveValues); | ||
Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements()); | ||
Ops.append({SI->getPointerOperand(), VL}); | ||
Value *Mask = Builder.getAllOnesMask(FVTy->getElementCount()); | ||
Ops.append({SI->getPointerOperand(), Mask, VL}); | ||
|
||
Builder.CreateCall(VssegNFunc, Ops); | ||
} else { | ||
|
@@ -24198,15 +24142,9 @@ bool RISCVTargetLowering::lowerInterleavedVPLoad( | |
|
||
Value *Return = nullptr; | ||
if (auto *FVTy = dyn_cast<FixedVectorType>(VTy)) { | ||
static const Intrinsic::ID FixedMaskedVlsegIntrIds[] = { | ||
Intrinsic::riscv_seg2_load_mask, Intrinsic::riscv_seg3_load_mask, | ||
Intrinsic::riscv_seg4_load_mask, Intrinsic::riscv_seg5_load_mask, | ||
Intrinsic::riscv_seg6_load_mask, Intrinsic::riscv_seg7_load_mask, | ||
Intrinsic::riscv_seg8_load_mask}; | ||
|
||
Return = Builder.CreateIntrinsic(FixedMaskedVlsegIntrIds[Factor - 2], | ||
{FVTy, XLenTy}, | ||
{Load->getArgOperand(0), Mask, EVL}); | ||
Return = | ||
Builder.CreateIntrinsic(FixedVlsegIntrIds[Factor - 2], {FVTy, XLenTy}, | ||
{Load->getArgOperand(0), Mask, EVL}); | ||
} else { | ||
static const Intrinsic::ID IntrMaskIds[] = { | ||
Intrinsic::riscv_vlseg2_mask, Intrinsic::riscv_vlseg3_mask, | ||
|
@@ -24318,15 +24256,9 @@ bool RISCVTargetLowering::lowerInterleavedVPStore( | |
XLenTy); | ||
|
||
if (auto *FVTy = dyn_cast<FixedVectorType>(VTy)) { | ||
static const Intrinsic::ID FixedMaskedVssegIntrIds[] = { | ||
Intrinsic::riscv_seg2_store_mask, Intrinsic::riscv_seg3_store_mask, | ||
Intrinsic::riscv_seg4_store_mask, Intrinsic::riscv_seg5_store_mask, | ||
Intrinsic::riscv_seg6_store_mask, Intrinsic::riscv_seg7_store_mask, | ||
Intrinsic::riscv_seg8_store_mask}; | ||
|
||
SmallVector<Value *, 8> Operands(InterleaveOperands); | ||
Operands.append({Store->getArgOperand(1), Mask, EVL}); | ||
Builder.CreateIntrinsic(FixedMaskedVssegIntrIds[Factor - 2], {FVTy, XLenTy}, | ||
Builder.CreateIntrinsic(FixedVssegIntrIds[Factor - 2], {FVTy, XLenTy}, | ||
Operands); | ||
return true; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the check here as pointed out by @lukel97 in another PR