Skip to content

Commit 301e640

Browse files
committed
Split away the strided segmented load implementation
We're going to put it in a separate patch in the future.
1 parent 425e1f1 commit 301e640

File tree

6 files changed

+6
-542
lines changed

6 files changed

+6
-542
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,19 +3181,6 @@ class TargetLoweringBase {
31813181
return false;
31823182
}
31833183

3184-
/// Lower a deinterleave intrinsic to a target specific strided load
3185-
/// intrinsic. Return true on success.
3186-
///
3187-
/// \p StridedLoad is the vp.strided.load instruction.
3188-
/// \p DI is the deinterleave intrinsic.
3189-
/// \p Factor is the interleave factor.
3190-
/// \p DeinterleaveRes is a list of deinterleaved results.
3191-
virtual bool lowerDeinterleaveIntrinsicToStridedLoad(
3192-
VPIntrinsic *StridedLoad, IntrinsicInst *DI, unsigned Factor,
3193-
ArrayRef<Value *> DeinterleaveRes) const {
3194-
return false;
3195-
}
3196-
31973184
/// Lower a deinterleave intrinsic to a target specific load intrinsic.
31983185
/// Return true on success. Currently only supports
31993186
/// llvm.vector.deinterleave2

llvm/lib/CodeGen/InterleavedAccessPass.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,13 @@ bool InterleavedAccessImpl::lowerInterleavedStore(
661661

662662
bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
663663
IntrinsicInst *DI, SmallSetVector<Instruction *, 32> &DeadInsts) {
664-
using namespace PatternMatch;
665-
SmallVector<Value *, 8> DeInterleaveResults;
666-
unsigned Factor = getVectorDeInterleaveFactor(DI, DeInterleaveResults);
664+
if (auto *VPLoad = dyn_cast<VPIntrinsic>(DI->getOperand(0))) {
665+
SmallVector<Value *, 8> DeInterleaveResults;
666+
unsigned Factor = getVectorDeInterleaveFactor(DI, DeInterleaveResults);
667+
if (!Factor)
668+
return false;
667669

668-
if (auto *VPLoad = dyn_cast<VPIntrinsic>(DI->getOperand(0));
669-
Factor && VPLoad) {
670+
using namespace PatternMatch;
670671
if (!match(VPLoad, m_OneUse(m_Intrinsic<Intrinsic::vp_load>())))
671672
return false;
672673

@@ -689,53 +690,6 @@ bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
689690
return true;
690691
}
691692

692-
// Match
693-
// %x = vp.strided.load ;; VPStridedLoad
694-
// %y = bitcast %x ;; BitCast
695-
// %y' = inttoptr %y
696-
// %z = deinterleave %y ;; DI
697-
if (Factor && isa<BitCastInst, IntToPtrInst>(DI->getOperand(0))) {
698-
auto *BitCast = cast<Instruction>(DI->getOperand(0));
699-
if (!BitCast->hasOneUse())
700-
return false;
701-
702-
Instruction *IntToPtrCast = nullptr;
703-
if (auto *BC = dyn_cast<BitCastInst>(BitCast->getOperand(0))) {
704-
IntToPtrCast = BitCast;
705-
BitCast = BC;
706-
}
707-
708-
// Match the type is
709-
// <VF x (factor * elementTy)> bitcast to <(VF * factor) x elementTy>
710-
Value *BitCastSrc = BitCast->getOperand(0);
711-
auto *BitCastSrcTy = dyn_cast<VectorType>(BitCastSrc->getType());
712-
auto *BitCastDstTy = cast<VectorType>(BitCast->getType());
713-
if (!BitCastSrcTy || (BitCastSrcTy->getElementCount() * Factor !=
714-
BitCastDstTy->getElementCount()))
715-
return false;
716-
717-
if (auto *VPStridedLoad = dyn_cast<VPIntrinsic>(BitCast->getOperand(0))) {
718-
if (VPStridedLoad->getIntrinsicID() !=
719-
Intrinsic::experimental_vp_strided_load ||
720-
!VPStridedLoad->hasOneUse())
721-
return false;
722-
723-
LLVM_DEBUG(dbgs() << "IA: Found a deinterleave intrinsic: " << *DI
724-
<< "\n");
725-
726-
if (!TLI->lowerDeinterleaveIntrinsicToStridedLoad(
727-
VPStridedLoad, DI, Factor, DeInterleaveResults))
728-
return false;
729-
730-
DeadInsts.push_back(DI);
731-
if (IntToPtrCast)
732-
DeadInsts.push_back(IntToPtrCast);
733-
DeadInsts.push_back(BitCast);
734-
DeadInsts.push_back(VPStridedLoad);
735-
return true;
736-
}
737-
}
738-
739693
LoadInst *LI = dyn_cast<LoadInst>(DI->getOperand(0));
740694

741695
if (!LI || !LI->hasOneUse() || !LI->isSimple())

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -22608,147 +22608,6 @@ bool RISCVTargetLowering::lowerInterleavedScalableStore(
2260822608
return true;
2260922609
}
2261022610

22611-
/// Lower an interleaved vp.strided.load into a vlssegN intrinsic.
22612-
///
22613-
/// E.g. Lower an interleaved vp.strided.load (Factor = 2):
22614-
/// %l = call <vscale x 2 x i16>
22615-
/// @llvm.experimental.vp.strided.load.nxv2i16.p0.i64(ptr %ptr,
22616-
/// %stride,
22617-
/// <all-true-mask>,
22618-
/// i32 %rvl)
22619-
/// %l.cast = bitcast <vscale x 2 x i16> %l to <vscale x 4 x i8>
22620-
/// %dl = tail call { <vscale x 2 x i8>, <vscale x 2 x i8> }
22621-
/// @llvm.vector.deinterleave2.nxv2i8(
22622-
/// <vscale x 4 x i8> %l.cast)
22623-
/// %r0 = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } %dl, 0
22624-
/// %r1 = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } %dl, 1
22625-
///
22626-
/// Into:
22627-
/// %ssl = call { <vscale x 2 x i8>, <vscale x 2 x i8> }
22628-
/// @llvm.riscv.vlseg2.nxv2i8.i64(<vscale x 32 x i8> poison,
22629-
/// <vscale x 32 x i8> poison,
22630-
/// %ptr,
22631-
/// %stride,
22632-
/// i64 %rvl)
22633-
/// %r0 = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } %ssl, 0
22634-
/// %r1 = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } %ssl, 1
22635-
///
22636-
/// NOTE: the deinterleave2 intrinsic and the bitcast instruction won't be
22637-
/// touched and is expected to be removed by the caller
22638-
bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToStridedLoad(
22639-
VPIntrinsic *StridedLoad, IntrinsicInst *DI, unsigned Factor,
22640-
ArrayRef<Value *> DeInterleaveResults) const {
22641-
using namespace llvm::PatternMatch;
22642-
Value *BasePtr, *Stride, *Mask, *EVL;
22643-
if (!match(StridedLoad, m_Intrinsic<Intrinsic::experimental_vp_strided_load>(
22644-
m_Value(BasePtr), m_Value(Stride), m_Value(Mask),
22645-
m_Value(EVL))))
22646-
return false;
22647-
22648-
[[maybe_unused]] auto *DISrcTy =
22649-
cast<VectorType>(DI->getOperand(0)->getType());
22650-
[[maybe_unused]] auto *LTy = cast<VectorType>(StridedLoad->getType());
22651-
auto &DL = StridedLoad->getModule()->getDataLayout();
22652-
assert(DL.getTypeAllocSizeInBits(DISrcTy) == DL.getTypeAllocSizeInBits(LTy) &&
22653-
"The primitive size of strided load and the source of deinterleave "
22654-
"should be the same.");
22655-
assert(DISrcTy->getElementCount() == LTy->getElementCount() * Factor &&
22656-
"ElementCount of source deinterleave should be equal to the "
22657-
"ElementCount of strided load multiplied by factor.");
22658-
22659-
auto *ResTy = cast<VectorType>(DeInterleaveResults[0]->getType());
22660-
22661-
Align Alignment =
22662-
cast<VPIntrinsic>(StridedLoad)->getPointerAlignment().valueOrOne();
22663-
if (!isLegalInterleavedAccessType(
22664-
ResTy, Factor, Alignment,
22665-
BasePtr->getType()->getPointerAddressSpace(), DL))
22666-
return false;
22667-
22668-
IRBuilder<> Builder(StridedLoad);
22669-
auto *XLenTy =
22670-
Type::getIntNTy(StridedLoad->getContext(), Subtarget.getXLen());
22671-
assert(Stride->getType() == XLenTy &&
22672-
"The type of stride must be the XLEN integer type.");
22673-
EVL = Builder.CreateZExtOrTrunc(EVL, XLenTy);
22674-
22675-
static const Intrinsic::ID IntrMaskIds[] = {
22676-
Intrinsic::riscv_vlsseg2_mask, Intrinsic::riscv_vlsseg3_mask,
22677-
Intrinsic::riscv_vlsseg4_mask, Intrinsic::riscv_vlsseg5_mask,
22678-
Intrinsic::riscv_vlsseg6_mask, Intrinsic::riscv_vlsseg7_mask,
22679-
Intrinsic::riscv_vlsseg8_mask,
22680-
};
22681-
22682-
static const Intrinsic::ID IntrIds[] = {
22683-
Intrinsic::riscv_vlsseg2, Intrinsic::riscv_vlsseg3,
22684-
Intrinsic::riscv_vlsseg4, Intrinsic::riscv_vlsseg5,
22685-
Intrinsic::riscv_vlsseg6, Intrinsic::riscv_vlsseg7,
22686-
Intrinsic::riscv_vlsseg8,
22687-
};
22688-
22689-
unsigned SEW = DL.getTypeSizeInBits(ResTy->getElementType());
22690-
unsigned NumElts = ResTy->getElementCount().getKnownMinValue();
22691-
Type *VecTupTy = TargetExtType::get(
22692-
StridedLoad->getContext(), "riscv.vector.tuple",
22693-
ScalableVectorType::get(Type::getInt8Ty(StridedLoad->getContext()),
22694-
NumElts * SEW / 8),
22695-
Factor);
22696-
22697-
Value *PoisonVal = PoisonValue::get(VecTupTy);
22698-
SmallVector<Value *, 7> Operands;
22699-
Operands.append({PoisonVal, BasePtr, Stride});
22700-
22701-
Intrinsic::ID VlssegNID = IntrIds[Factor - 2];
22702-
bool IsMasked = !match(Mask, m_AllOnes());
22703-
if (IsMasked) {
22704-
VlssegNID = IntrMaskIds[Factor - 2];
22705-
Operands.push_back(Mask);
22706-
}
22707-
22708-
Operands.push_back(EVL);
22709-
22710-
// Set the tail policy to tail-agnostic, mask-agnostic (tama) for masked
22711-
// intrinsics
22712-
if (IsMasked)
22713-
Operands.push_back(ConstantInt::get(XLenTy, 3));
22714-
22715-
Operands.push_back(ConstantInt::get(XLenTy, Log2_64(SEW)));
22716-
22717-
Function *VlssegNFunc;
22718-
if (IsMasked) {
22719-
VlssegNFunc = Intrinsic::getOrInsertDeclaration(
22720-
StridedLoad->getModule(), VlssegNID,
22721-
{VecTupTy, EVL->getType(), Mask->getType()});
22722-
} else {
22723-
VlssegNFunc = Intrinsic::getOrInsertDeclaration(
22724-
StridedLoad->getModule(), VlssegNID, {VecTupTy, EVL->getType()});
22725-
}
22726-
CallInst *VlssegN = Builder.CreateCall(VlssegNFunc, Operands);
22727-
22728-
SmallVector<Type *, 8> AggrTypes{Factor, ResTy};
22729-
Value *Return =
22730-
PoisonValue::get(StructType::get(StridedLoad->getContext(), AggrTypes));
22731-
Function *VecExtractFunc = Intrinsic::getOrInsertDeclaration(
22732-
StridedLoad->getModule(), Intrinsic::riscv_tuple_extract,
22733-
{ResTy, VecTupTy});
22734-
for (unsigned i = 0; i < Factor; ++i) {
22735-
Value *VecExtract =
22736-
Builder.CreateCall(VecExtractFunc, {VlssegN, Builder.getInt32(i)});
22737-
Return = Builder.CreateInsertValue(Return, VecExtract, i);
22738-
}
22739-
22740-
for (auto [Idx, DIO] : enumerate(DeInterleaveResults)) {
22741-
// We have to create a brand new ExtractValue to replace each
22742-
// of these old ExtractValue instructions.
22743-
Value *NewEV =
22744-
Builder.CreateExtractValue(Return, {static_cast<unsigned>(Idx)});
22745-
DIO->replaceAllUsesWith(NewEV);
22746-
}
22747-
DI->replaceAllUsesWith(UndefValue::get(DI->getType()));
22748-
22749-
return true;
22750-
}
22751-
2275222611
MachineInstr *
2275322612
RISCVTargetLowering::EmitKCFICheck(MachineBasicBlock &MBB,
2275422613
MachineBasicBlock::instr_iterator &MBBI,

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,6 @@ class RISCVTargetLowering : public TargetLowering {
916916
VPIntrinsic *Store, Value *Mask, IntrinsicInst *InterleaveIntrin,
917917
unsigned Factor, ArrayRef<Value *> InterleaveOps) const override;
918918

919-
bool lowerDeinterleaveIntrinsicToStridedLoad(
920-
VPIntrinsic *StridedLoad, IntrinsicInst *DI, unsigned Factor,
921-
ArrayRef<Value *> DeinterleaveRes) const override;
922-
923919
bool supportKCFIBundles() const override { return true; }
924920

925921
SDValue expandIndirectJTBranch(const SDLoc &dl, SDValue Value, SDValue Addr,

0 commit comments

Comments
 (0)