Skip to content

Commit 1e62f9f

Browse files
committed
!fixup address comments, thanks
1 parent 0d04499 commit 1e62f9f

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,19 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
333333
LastLane = 0;
334334
}
335335

336-
assert(IsSingleScalar && "must be a single-scalar at this point");
337336
// We need to construct the vector value for a single-scalar value by
338337
// broadcasting the scalar to all lanes.
339-
auto *LastInst = cast<Instruction>(get(Def, LastLane));
338+
// TODO: Replace by introducing Broadcast VPInstructions.
339+
assert(IsSingleScalar && "must be a single-scalar at this point");
340340
// Set the insert point after the last scalarized instruction or after the
341341
// last PHI, if LastInst is a PHI. This ensures the insertelement sequence
342342
// will directly follow the scalar definitions.
343343
auto OldIP = Builder.saveIP();
344+
auto *LastInst = cast<Instruction>(get(Def, LastLane));
344345
auto NewIP = isa<PHINode>(LastInst)
345346
? LastInst->getParent()->getFirstNonPHIIt()
346347
: std::next(BasicBlock::iterator(LastInst));
347348
Builder.SetInsertPoint(&*NewIP);
348-
349349
Value *VectorValue = GetBroadcastInstrs(ScalarValue);
350350
set(Def, VectorValue);
351351
Builder.restoreIP(OldIP);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,13 +3542,12 @@ void VPlanTransforms::materializeBuildVectors(VPlan &Plan) {
35423542
// VPReplicateRegion::execute(), via shouldPack().
35433543
// TODO: materialize build vectors for replicating recipes in replicating
35443544
// regions.
3545-
// TODO: materialize build vectors for VPInstructions.
35463545
for (VPBasicBlock *VPBB :
35473546
concat<VPBasicBlock *>(VPBBsOutsideLoopRegion, VPBBsInsideLoopRegion)) {
35483547
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
3549-
auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
3550-
if (!DefR || !isa<VPReplicateRecipe, VPInstruction>(DefR))
3548+
if (!isa<VPReplicateRecipe, VPInstruction>(&R))
35513549
continue;
3550+
auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
35523551
auto UsesVectorOrInsideReplicateRegion = [DefR, LoopRegion](VPUser *U) {
35533552
VPRegionBlock *ParentRegion =
35543553
cast<VPRecipeBase>(U)->getParent()->getParent();

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct VPlanTransforms {
158158
/// Explicitly unroll \p Plan by \p UF.
159159
static void unrollByUF(VPlan &Plan, unsigned UF);
160160

161-
/// Replace each VPReplicateRecipe and replicating VPInstruction outside on
161+
/// Replace each replicating VPReplicateRecipe and VPInstruction outside of
162162
/// any replicate region in \p Plan with \p VF single-scalar recipes.
163163
/// TODO: Also replicate VPReplicateRecipes inside replicate regions, thereby
164164
/// dissolving the latter.

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ void VPlanTransforms::unrollByUF(VPlan &Plan, unsigned UF) {
463463
VPlanTransforms::removeDeadRecipes(Plan);
464464
}
465465

466-
/// Create a single-scalar clone of \p DefR for lane \p Lane. Use \p
467-
/// Def2LaneDefs to look up scalar definitions for operands of \DefR.
466+
/// Create a single-scalar clone of \p DefR (must either be a VPReplicateRecipe
467+
/// or VPInstruction) for lane \p Lane. Use \p Def2LaneDefs to look up scalar
468+
/// definitions for operands of \DefR.
468469
static VPRecipeWithIRFlags *
469470
cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
470471
VPRecipeWithIRFlags *DefR, VPLane Lane,
@@ -503,10 +504,15 @@ cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
503504

504505
VPRecipeWithIRFlags *New;
505506
if (auto *RepR = dyn_cast<VPReplicateRecipe>(DefR)) {
507+
// TODO: have cloning of replicate recipes also provide the desired result
508+
// coupled with setting its operands to NewOps (deriving IsSingleScalar and
509+
// Mask from the operands?)
506510
New =
507511
new VPReplicateRecipe(RepR->getUnderlyingInstr(), NewOps,
508512
/*IsSingleScalar=*/true, /*Mask=*/nullptr, *RepR);
509513
} else {
514+
assert(isa<VPInstruction>(DefR) &&
515+
"DefR must either be a VPReplicateRecipe or VPInstruction");
510516
New = DefR->clone();
511517
for (const auto &[Idx, Op] : enumerate(NewOps)) {
512518
New->setOperand(Idx, Op);
@@ -538,15 +544,15 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
538544
SmallVector<VPRecipeBase *> ToRemove;
539545
for (VPBasicBlock *VPBB : VPBBsToUnroll) {
540546
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
541-
auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
542-
if (!DefR || !isa<VPInstruction, VPReplicateRecipe>(DefR))
543-
continue;
544-
if ((isa<VPReplicateRecipe>(DefR) &&
545-
cast<VPReplicateRecipe>(DefR)->isSingleScalar()) ||
546-
(isa<VPInstruction>(DefR) &&
547-
!cast<VPInstruction>(DefR)->doesGeneratePerAllLanes()))
547+
if (!isa<VPInstruction, VPReplicateRecipe>(&R) ||
548+
(isa<VPReplicateRecipe>(&R) &&
549+
cast<VPReplicateRecipe>(&R)->isSingleScalar()) ||
550+
(isa<VPInstruction>(&R) &&
551+
!cast<VPInstruction>(&R)->doesGeneratePerAllLanes()))
548552
continue;
549553

554+
auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
555+
550556
VPBuilder Builder(DefR);
551557
if (DefR->getNumUsers() == 0) {
552558
if (isa<StoreInst>(DefR->getUnderlyingInstr()) &&

0 commit comments

Comments
 (0)