Skip to content

Commit 965f351

Browse files
committed
Fix the interleave EVL
1 parent 5daa4db commit 965f351

File tree

5 files changed

+103
-54
lines changed

5 files changed

+103
-54
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,9 @@ void VPInterleaveEVLRecipe::execute(VPTransformState &State) {
36953695
VPValue *Addr = getAddr();
36963696
Value *ResAddr = State.get(Addr, VPLane(0));
36973697
Value *EVL = State.get(getEVL(), VPLane(0));
3698+
Value *InterleaveEVL = State.Builder.CreateMul(
3699+
EVL, ConstantInt::get(EVL->getType(), InterleaveFactor), "interleave.evl",
3700+
/* NUW= */ true, /* NSW= */ true);
36983701
LLVMContext &Ctx = State.Builder.getContext();
36993702

37003703
auto CreateGroupMask = [&BlockInMask, &State,
@@ -3714,9 +3717,9 @@ void VPInterleaveEVLRecipe::execute(VPTransformState &State) {
37143717
const DataLayout &DL = Instr->getDataLayout();
37153718
// Vectorize the interleaved load group.
37163719
if (isa<LoadInst>(Instr)) {
3717-
CallInst *NewLoad = State.Builder.CreateIntrinsic(VecTy, Intrinsic::vp_load,
3718-
{ResAddr, GroupMask, EVL},
3719-
nullptr, "wide.vp.load");
3720+
CallInst *NewLoad = State.Builder.CreateIntrinsic(
3721+
VecTy, Intrinsic::vp_load, {ResAddr, GroupMask, InterleaveEVL}, nullptr,
3722+
"wide.vp.load");
37203723
NewLoad->addParamAttr(0,
37213724
Attribute::getWithAlignment(Ctx, Group->getAlign()));
37223725

@@ -3782,9 +3785,9 @@ void VPInterleaveEVLRecipe::execute(VPTransformState &State) {
37823785

37833786
// Interleave all the smaller vectors into one wider vector.
37843787
Value *IVec = interleaveVectors(State.Builder, StoredVecs, "interleaved.vec");
3785-
CallInst *NewStore = State.Builder.CreateIntrinsic(
3786-
Type::getVoidTy(EVL->getContext()), Intrinsic::vp_store,
3787-
{IVec, ResAddr, GroupMask, EVL});
3788+
CallInst *NewStore =
3789+
State.Builder.CreateIntrinsic(Type::getVoidTy(Ctx), Intrinsic::vp_store,
3790+
{IVec, ResAddr, GroupMask, InterleaveEVL});
37883791
NewStore->addParamAttr(1,
37893792
Attribute::getWithAlignment(Ctx, Group->getAlign()));
37903793

llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ define void @gather_interleave_group_with_dead_insert_pos(i64 %N, ptr noalias %s
407407
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[DOTSPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
408408
; CHECK-NEXT: [[OFFSET_IDX:%.*]] = mul i64 [[EVL_BASED_IV]], 2
409409
; CHECK-NEXT: [[TMP22:%.*]] = getelementptr i8, ptr [[SRC]], i64 [[OFFSET_IDX]]
410-
; CHECK-NEXT: [[WIDE_MASKED_VEC:%.*]] = call <vscale x 8 x i8> @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP22]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP10]])
410+
; CHECK-NEXT: [[INTERLEAVE_EVL:%.*]] = mul nuw nsw i32 [[TMP10]], 2
411+
; CHECK-NEXT: [[WIDE_MASKED_VEC:%.*]] = call <vscale x 8 x i8> @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP22]], <vscale x 8 x i1> splat (i1 true), i32 [[INTERLEAVE_EVL]])
411412
; CHECK-NEXT: [[STRIDED_VEC:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.vector.deinterleave2.nxv8i8(<vscale x 8 x i8> [[WIDE_MASKED_VEC]])
412413
; CHECK-NEXT: [[TMP23:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[STRIDED_VEC]], 0
413414
; CHECK-NEXT: [[TMP17:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[STRIDED_VEC]], 1

0 commit comments

Comments
 (0)