@@ -22608,147 +22608,6 @@ bool RISCVTargetLowering::lowerInterleavedScalableStore(
22608
22608
return true;
22609
22609
}
22610
22610
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
-
22752
22611
MachineInstr *
22753
22612
RISCVTargetLowering::EmitKCFICheck(MachineBasicBlock &MBB,
22754
22613
MachineBasicBlock::instr_iterator &MBBI,
0 commit comments