Skip to content

Commit 0ec4476

Browse files
committed
[LV][EVL] Address code review comments
1 parent 7f20e34 commit 0ec4476

File tree

5 files changed

+248
-534
lines changed

5 files changed

+248
-534
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
15931593
Type *getResultType() const { return ResultTy; }
15941594
};
15951595

1596-
// A recipe for widening cast operation with vector-predication intrinsics with
1596+
/// A recipe for widening cast operation with vector-predication intrinsics with
15971597
/// explicit vector length (EVL).
15981598
class VPWidenCastEVLRecipe : public VPWidenCastRecipe {
15991599
using VPRecipeWithIRFlags::transferFlags;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+12-23
Original file line numberDiff line numberDiff line change
@@ -1424,40 +1424,29 @@ void VPWidenCastRecipe::execute(VPTransformState &State) {
14241424

14251425
void VPWidenCastEVLRecipe::execute(VPTransformState &State) {
14261426
unsigned Opcode = getOpcode();
1427-
auto Inst = cast<CastInst>(getUnderlyingInstr());
14281427
State.setDebugLocFrom(getDebugLoc());
1429-
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
1430-
"explicit vector length.");
1428+
Value *SrcVal = State.get(getOperand(0));
1429+
VectorType *DsType = VectorType::get(getResultType(), State.VF);
14311430

1432-
if (Inst->isCast()) {
1433-
Value *SrcVal = State.get(getOperand(0), 0);
1434-
VectorType *DsType = VectorType::get(getResultType(), State.VF);
1435-
1436-
IRBuilderBase &BuilderIR = State.Builder;
1437-
VectorBuilder Builder(BuilderIR);
1438-
Value *Mask = BuilderIR.CreateVectorSplat(State.VF, BuilderIR.getTrue());
1439-
Builder.setMask(Mask).setEVL(State.get(getEVL(), 0, /*NeedsScalar=*/true));
1440-
1441-
Value *VPInst =
1442-
Builder.createVectorInstruction(Opcode, DsType, {SrcVal}, "vp.cast");
1431+
IRBuilderBase &BuilderIR = State.Builder;
1432+
VectorBuilder Builder(BuilderIR);
1433+
Value *Mask = BuilderIR.CreateVectorSplat(State.VF, BuilderIR.getTrue());
1434+
Builder.setMask(Mask).setEVL(State.get(getEVL(), /*NeedsScalar=*/true));
14431435

1444-
if (VPInst) {
1445-
if (auto *VecOp = dyn_cast<CastInst>(VPInst))
1446-
VecOp->copyIRFlags(getUnderlyingInstr());
1447-
}
1436+
Value *VPInst =
1437+
Builder.createVectorInstruction(Opcode, DsType, {SrcVal}, "vp.cast");
14481438

1449-
State.set(this, VPInst, 0);
1450-
State.addMetadata(VPInst,
1451-
dyn_cast_or_null<Instruction>(getUnderlyingValue()));
1452-
}
1439+
State.set(this, VPInst, 0);
1440+
State.addMetadata(VPInst,
1441+
dyn_cast_or_null<Instruction>(getUnderlyingValue()));
14531442
}
14541443

14551444
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
14561445
void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
14571446
VPSlotTracker &SlotTracker) const {
14581447
O << Indent << "WIDEN-CAST ";
14591448
printAsOperand(O, SlotTracker);
1460-
O << " = " << Instruction::getOpcodeName(Opcode);
1449+
O << " = " << Instruction::getOpcodeName(Opcode) << " ";
14611450
printFlags(O);
14621451
printOperands(O, SlotTracker);
14631452
O << " to " << *getResultType();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1381,9 +1381,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
13811381
})
13821382
.Case<VPWidenCastRecipe>(
13831383
[&](VPWidenCastRecipe *W) -> VPRecipeBase * {
1384-
auto Inst = cast<CastInst>(W->getUnderlyingInstr());
1385-
if (!Inst->isCast())
1386-
return nullptr;
13871384
return new VPWidenCastEVLRecipe(*W, EVL);
13881385
})
13891386
.Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,12 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
141141
.Case<VPWidenStoreEVLRecipe>([&](const VPWidenStoreEVLRecipe *S) {
142142
return VerifyEVLUse(*S, 2);
143143
})
144-
.Case<VPWidenLoadEVLRecipe>([&](const VPWidenLoadEVLRecipe *L) {
145-
return VerifyEVLUse(*L, 1);
146-
})
144+
.Case<VPWidenLoadEVLRecipe, VPWidenCastEVLRecipe>(
145+
[&](const VPRecipeBase *C) { return VerifyEVLUse(*C, 1); })
147146
.Case<VPWidenEVLRecipe>([&](const VPWidenEVLRecipe *W) {
148147
return VerifyEVLUse(
149148
*W, Instruction::isUnaryOp(W->getOpcode()) ? 1 : 2);
150149
})
151-
.Case<VPWidenCastEVLRecipe>([&](const VPWidenCastEVLRecipe *C) {
152-
return VerifyEVLUse(*C, 1);
153-
})
154150
.Case<VPReductionEVLRecipe>([&](const VPReductionEVLRecipe *R) {
155151
return VerifyEVLUse(*R, 2);
156152
})

0 commit comments

Comments
 (0)