@@ -83,6 +83,7 @@ bool VPRecipeBase::mayWriteToMemory() const {
8383 case VPWidenCastSC:
8484 case VPWidenGEPSC:
8585 case VPWidenIntOrFpInductionSC:
86+ case VPWidenStridedLoadSC:
8687 case VPWidenLoadEVLSC:
8788 case VPWidenLoadSC:
8889 case VPWidenPHISC:
@@ -106,6 +107,7 @@ bool VPRecipeBase::mayReadFromMemory() const {
106107 return cast<VPExpressionRecipe>(this )->mayReadOrWriteMemory ();
107108 case VPInstructionSC:
108109 return cast<VPInstruction>(this )->opcodeMayReadOrWriteFromMemory ();
110+ case VPWidenStridedLoadSC:
109111 case VPWidenLoadEVLSC:
110112 case VPWidenLoadSC:
111113 return true ;
@@ -189,6 +191,7 @@ bool VPRecipeBase::mayHaveSideEffects() const {
189191 case VPInterleaveEVLSC:
190192 case VPInterleaveSC:
191193 return mayWriteToMemory ();
194+ case VPWidenStridedLoadSC:
192195 case VPWidenLoadEVLSC:
193196 case VPWidenLoadSC:
194197 case VPWidenStoreEVLSC:
@@ -3497,9 +3500,11 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
34973500 const Align Alignment = getLoadStoreAlignment (&Ingredient);
34983501 unsigned AS = cast<PointerType>(Ctx.Types .inferScalarType (getAddr ()))
34993502 ->getAddressSpace ();
3500- unsigned Opcode = isa<VPWidenLoadRecipe, VPWidenLoadEVLRecipe>(this )
3501- ? Instruction::Load
3502- : Instruction::Store;
3503+ unsigned Opcode =
3504+ isa<VPWidenLoadRecipe, VPWidenLoadEVLRecipe, VPWidenStridedLoadRecipe>(
3505+ this )
3506+ ? Instruction::Load
3507+ : Instruction::Store;
35033508
35043509 if (!Consecutive) {
35053510 // TODO: Using the original IR may not be accurate.
@@ -3509,8 +3514,11 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
35093514 " Inconsecutive memory access should not have the order." );
35103515
35113516 const Value *Ptr = getLoadStorePointerOperand (&Ingredient);
3512- Type *PtrTy = Ptr->getType ();
3517+ if (isa<VPWidenStridedLoadRecipe>(this ))
3518+ return Ctx.TTI .getStridedMemoryOpCost (
3519+ Opcode, Ty, Ptr, IsMasked, Alignment, Ctx.CostKind , &Ingredient);
35133520
3521+ Type *PtrTy = Ptr->getType ();
35143522 // If the address value is uniform across all lanes, then the address can be
35153523 // calculated with scalar type and broadcast.
35163524 if (!vputils::isSingleScalar (getAddr ()))
@@ -3665,6 +3673,47 @@ void VPWidenLoadEVLRecipe::print(raw_ostream &O, const Twine &Indent,
36653673}
36663674#endif
36673675
3676+ void VPWidenStridedLoadRecipe::execute (VPTransformState &State) {
3677+ Type *ScalarDataTy = getLoadStoreType (&Ingredient);
3678+ auto *DataTy = VectorType::get (ScalarDataTy, State.VF );
3679+ const Align Alignment = getLoadStoreAlignment (&Ingredient);
3680+
3681+ auto &Builder = State.Builder ;
3682+ Value *Addr = State.get (getAddr (), /* IsScalar*/ true );
3683+ Value *StrideInBytes = State.get (getStride (), /* IsScalar*/ true );
3684+ Value *Mask = nullptr ;
3685+ if (VPValue *VPMask = getMask ())
3686+ Mask = State.get (VPMask);
3687+ else
3688+ Mask = Builder.CreateVectorSplat (State.VF , Builder.getTrue ());
3689+ Value *RunTimeVF = Builder.CreateZExtOrTrunc (State.get (getVF (), VPLane (0 )),
3690+ Builder.getInt32Ty ());
3691+
3692+ auto *PtrTy = Addr->getType ();
3693+ auto *StrideTy = StrideInBytes->getType ();
3694+ CallInst *NewLI = Builder.CreateIntrinsic (
3695+ Intrinsic::experimental_vp_strided_load, {DataTy, PtrTy, StrideTy},
3696+ {Addr, StrideInBytes, Mask, RunTimeVF}, nullptr , " wide.strided.load" );
3697+ NewLI->addParamAttr (
3698+ 0 , Attribute::getWithAlignment (NewLI->getContext (), Alignment));
3699+ applyMetadata (*NewLI);
3700+ State.set (this , NewLI);
3701+ }
3702+
3703+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3704+ void VPWidenStridedLoadRecipe::print (raw_ostream &O, const Twine &Indent,
3705+ VPSlotTracker &SlotTracker) const {
3706+ O << Indent << " WIDEN " ;
3707+ printAsOperand (O, SlotTracker);
3708+ O << " = load " ;
3709+ getAddr ()->printAsOperand (O, SlotTracker);
3710+ O << " , stride = " ;
3711+ getStride ()->printAsOperand (O, SlotTracker);
3712+ O << " , runtimeVF = " ;
3713+ getVF ()->printAsOperand (O, SlotTracker);
3714+ }
3715+ #endif
3716+
36683717void VPWidenStoreRecipe::execute (VPTransformState &State) {
36693718 VPValue *StoredVPValue = getStoredValue ();
36703719 bool CreateScatter = !isConsecutive ();
0 commit comments