Skip to content

Commit ee4b5f4

Browse files
committed
[LV][EVL] Address code review comments
1 parent 44ebfbd commit ee4b5f4

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
@@ -1587,7 +1587,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
15871587
Type *getResultType() const { return ResultTy; }
15881588
};
15891589

1590-
// A recipe for widening cast operation with vector-predication intrinsics with
1590+
/// A recipe for widening cast operation with vector-predication intrinsics with
15911591
/// explicit vector length (EVL).
15921592
class VPWidenCastEVLRecipe : public VPWidenCastRecipe {
15931593
using VPRecipeWithIRFlags::transferFlags;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

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

13461346
void VPWidenCastEVLRecipe::execute(VPTransformState &State) {
13471347
unsigned Opcode = getOpcode();
1348-
auto Inst = cast<CastInst>(getUnderlyingInstr());
13491348
State.setDebugLocFrom(getDebugLoc());
1350-
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
1351-
"explicit vector length.");
1349+
Value *SrcVal = State.get(getOperand(0));
1350+
VectorType *DsType = VectorType::get(getResultType(), State.VF);
13521351

1353-
if (Inst->isCast()) {
1354-
Value *SrcVal = State.get(getOperand(0), 0);
1355-
VectorType *DsType = VectorType::get(getResultType(), State.VF);
1356-
1357-
IRBuilderBase &BuilderIR = State.Builder;
1358-
VectorBuilder Builder(BuilderIR);
1359-
Value *Mask = BuilderIR.CreateVectorSplat(State.VF, BuilderIR.getTrue());
1360-
Builder.setMask(Mask).setEVL(State.get(getEVL(), 0, /*NeedsScalar=*/true));
1361-
1362-
Value *VPInst =
1363-
Builder.createVectorInstruction(Opcode, DsType, {SrcVal}, "vp.cast");
1352+
IRBuilderBase &BuilderIR = State.Builder;
1353+
VectorBuilder Builder(BuilderIR);
1354+
Value *Mask = BuilderIR.CreateVectorSplat(State.VF, BuilderIR.getTrue());
1355+
Builder.setMask(Mask).setEVL(State.get(getEVL(), /*NeedsScalar=*/true));
13641356

1365-
if (VPInst) {
1366-
if (auto *VecOp = dyn_cast<CastInst>(VPInst))
1367-
VecOp->copyIRFlags(getUnderlyingInstr());
1368-
}
1357+
Value *VPInst =
1358+
Builder.createVectorInstruction(Opcode, DsType, {SrcVal}, "vp.cast");
13691359

1370-
State.set(this, VPInst, 0);
1371-
State.addMetadata(VPInst,
1372-
dyn_cast_or_null<Instruction>(getUnderlyingValue()));
1373-
}
1360+
State.set(this, VPInst, 0);
1361+
State.addMetadata(VPInst,
1362+
dyn_cast_or_null<Instruction>(getUnderlyingValue()));
13741363
}
13751364

13761365
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
13771366
void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
13781367
VPSlotTracker &SlotTracker) const {
13791368
O << Indent << "WIDEN-CAST ";
13801369
printAsOperand(O, SlotTracker);
1381-
O << " = " << Instruction::getOpcodeName(Opcode);
1370+
O << " = " << Instruction::getOpcodeName(Opcode) << " ";
13821371
printFlags(O);
13831372
printOperands(O, SlotTracker);
13841373
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)