Skip to content

Commit b4670f6

Browse files
committed
!fixup address latest comments, thanks
1 parent b082242 commit b4670f6

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,12 @@ void VPBasicBlock::connectToPredecessors(VPTransformState &State) {
450450
if (ParentLoop && !State.LI->getLoopFor(NewBB))
451451
ParentLoop->addBasicBlockToLoop(NewBB, *State.LI);
452452

453-
auto Preds = to_vector(getHierarchicalPredecessors());
453+
SmallVector<VPBlockBase *> Preds;
454454
if (VPBlockUtils::isHeader(this, State.VPDT)) {
455455
// There's no block for the latch yet, connect to the preheader only.
456-
Preds = {Preds[0]};
456+
Preds = {getPredecessors()[0]};
457+
} else {
458+
Preds = to_vector(getPredecessors());
457459
}
458460

459461
// Hook up the new basic block to its predecessors.
@@ -879,11 +881,10 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
879881
}
880882
#endif
881883

882-
void VPRegionBlock::removeRegion() {
884+
void VPRegionBlock::dissolveToCFGLoop() {
883885
auto *Header = cast<VPBasicBlock>(getEntry());
884886
VPBlockBase *Preheader = getSinglePredecessor();
885-
auto *Exiting = cast<VPBasicBlock>(getExiting());
886-
887+
auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
887888
VPBlockBase *Middle = getSingleSuccessor();
888889
VPBlockUtils::disconnectBlocks(Preheader, this);
889890
VPBlockUtils::disconnectBlocks(this, Middle);
@@ -892,8 +893,8 @@ void VPRegionBlock::removeRegion() {
892893
VPB->setParent(getParent());
893894

894895
VPBlockUtils::connectBlocks(Preheader, Header);
895-
VPBlockUtils::connectBlocks(Exiting, Middle);
896-
VPBlockUtils::connectBlocks(Exiting, Header);
896+
VPBlockUtils::connectBlocks(ExitingLatch, Middle);
897+
VPBlockUtils::connectBlocks(ExitingLatch, Header);
897898
}
898899

899900
VPlan::VPlan(Loop *L) {
@@ -1005,6 +1006,8 @@ void VPlan::execute(VPTransformState *State) {
10051006
for (VPBlockBase *Block : RPOT)
10061007
Block->execute(State);
10071008

1009+
State->CFG.DTU.flush();
1010+
10081011
VPBasicBlock *Header = vputils::getFirstLoopHeader(*this, State->VPDT);
10091012
if (!Header)
10101013
return;
@@ -1427,7 +1430,7 @@ static bool isDefinedInsideLoopRegions(const VPValue *VPV) {
14271430
DefR->getParent()->getEnclosingLoopRegion());
14281431
}
14291432

1430-
bool VPValue::isDefinedOutsideLoop() const {
1433+
bool VPValue::isDefinedOutsideLoopRegions() const {
14311434
return !isDefinedInsideLoopRegions(this);
14321435
}
14331436
void VPValue::replaceAllUsesWith(VPValue *New) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,9 @@ struct VPWidenSelectRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
16311631
return getOperand(0);
16321632
}
16331633

1634-
bool isInvariantCond() const { return getCond()->isDefinedOutsideLoop(); }
1634+
bool isInvariantCond() const {
1635+
return getCond()->isDefinedOutsideLoopRegions();
1636+
}
16351637

16361638
/// Returns true if the recipe only uses the first lane of operand \p Op.
16371639
bool onlyFirstLaneUsed(const VPValue *Op) const override {
@@ -1644,16 +1646,17 @@ struct VPWidenSelectRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
16441646
/// A recipe for handling GEP instructions.
16451647
class VPWidenGEPRecipe : public VPRecipeWithIRFlags {
16461648
bool isPointerLoopInvariant() const {
1647-
return getOperand(0)->isDefinedOutsideLoop();
1649+
return getOperand(0)->isDefinedOutsideLoopRegions();
16481650
}
16491651

16501652
bool isIndexLoopInvariant(unsigned I) const {
1651-
return getOperand(I + 1)->isDefinedOutsideLoop();
1653+
return getOperand(I + 1)->isDefinedOutsideLoopRegions();
16521654
}
16531655

16541656
bool areAllOperandsInvariant() const {
1655-
return all_of(operands(),
1656-
[](VPValue *Op) { return Op->isDefinedOutsideLoop(); });
1657+
return all_of(operands(), [](VPValue *Op) {
1658+
return Op->isDefinedOutsideLoopRegions();
1659+
});
16571660
}
16581661

16591662
public:
@@ -3868,8 +3871,8 @@ class VPRegionBlock : public VPBlockBase {
38683871
VPRegionBlock *clone() override;
38693872

38703873
/// Remove the current region from its VPlan, connecting its predecessor to
3871-
/// its entry and exiting block to its successor.
3872-
void removeRegion();
3874+
/// its entry, and its exiting block to its successor.
3875+
void dissolveToCFGLoop();
38733876
};
38743877

38753878
/// VPlan models a candidate for vectorization, encoding various decisions take

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Value *VPInstruction::generatePerLane(VPTransformState &State,
465465
/// Create a conditional branch using \p Cond branching to the successors of \p
466466
/// VPBB. Note that the first successor is always forward (i.e. not created yet)
467467
/// while the second successor may already have been created (if it is a header
468-
/// block and VPBB is a header).
468+
/// block and VPBB is a latch).
469469
static BranchInst *createCondBranch(Value *Cond, VPBasicBlock *VPBB,
470470
VPTransformState &State) {
471471
// Replace the temporary unreachable terminator with a new conditional
@@ -1557,7 +1557,7 @@ void VPWidenSelectRecipe::execute(VPTransformState &State) {
15571557
InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF,
15581558
VPCostContext &Ctx) const {
15591559
SelectInst *SI = cast<SelectInst>(getUnderlyingValue());
1560-
bool ScalarCond = getOperand(0)->isDefinedOutsideLoop();
1560+
bool ScalarCond = getOperand(0)->isDefinedOutsideLoopRegions();
15611561
Type *ScalarTy = Ctx.Types.inferScalarType(this);
15621562
Type *VectorTy = toVectorTy(Ctx.Types.inferScalarType(this), VF);
15631563

@@ -1778,7 +1778,7 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
17781778
TargetTransformInfo::OperandValueInfo RHSInfo = Ctx.getOperandInfo(RHS);
17791779

17801780
if (RHSInfo.Kind == TargetTransformInfo::OK_AnyValue &&
1781-
getOperand(1)->isDefinedOutsideLoop())
1781+
getOperand(1)->isDefinedOutsideLoopRegions())
17821782
RHSInfo.Kind = TargetTransformInfo::OK_UniformValue;
17831783
Type *VectorTy = toVectorTy(Ctx.Types.inferScalarType(this), VF);
17841784
Instruction *CtxI = dyn_cast_or_null<Instruction>(getUnderlyingValue());
@@ -2677,12 +2677,13 @@ static void scalarizeInstruction(const Instruction *Instr,
26772677
if (auto *II = dyn_cast<AssumeInst>(Cloned))
26782678
State.AC->registerAssumption(II);
26792679

2680-
assert((RepRecipe->getParent()->getParent() ||
2681-
!RepRecipe->getParent()->getPlan()->getVectorLoopRegion() ||
2682-
all_of(RepRecipe->operands(),
2683-
[](VPValue *Op) { return Op->isDefinedOutsideLoop(); })) &&
2684-
"Expected a recipe is either within a region or all of its operands "
2685-
"are defined outside the vectorized region.");
2680+
assert(
2681+
(RepRecipe->getParent()->getParent() ||
2682+
!RepRecipe->getParent()->getPlan()->getVectorLoopRegion() ||
2683+
all_of(RepRecipe->operands(),
2684+
[](VPValue *Op) { return Op->isDefinedOutsideLoopRegions(); })) &&
2685+
"Expected a recipe is either within a region or all of its operands "
2686+
"are defined outside the vectorized region.");
26862687
}
26872688

26882689
void VPReplicateRecipe::execute(VPTransformState &State) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,9 @@ static void licm(VPlan &Plan) {
17361736
// TODO: Relax checks in the future, e.g. we could also hoist reads, if
17371737
// their memory location is not modified in the vector loop.
17381738
if (R.mayHaveSideEffects() || R.mayReadFromMemory() || R.isPhi() ||
1739-
any_of(R.operands(),
1740-
[](VPValue *Op) { return !Op->isDefinedOutsideLoop(); }))
1739+
any_of(R.operands(), [](VPValue *Op) {
1740+
return !Op->isDefinedOutsideLoopRegions();
1741+
}))
17411742
continue;
17421743
R.moveBefore(*Preheader, Preheader->end());
17431744
}
@@ -2514,7 +2515,7 @@ void VPlanTransforms::dissolveLoopRegions(VPlan &Plan) {
25142515
LoopRegions.push_back(R);
25152516
}
25162517
for (VPRegionBlock *R : LoopRegions)
2517-
R->removeRegion();
2518+
R->dissolveToCFGLoop();
25182519
}
25192520

25202521
// Expand VPExtendedReductionRecipe to VPWidenCastRecipe + VPReductionRecipe.

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void UnrollState::unrollRecipeByUF(VPRecipeBase &R) {
246246
}
247247
if (auto *RepR = dyn_cast<VPReplicateRecipe>(&R)) {
248248
if (isa<StoreInst>(RepR->getUnderlyingValue()) &&
249-
RepR->getOperand(1)->isDefinedOutsideLoop()) {
249+
RepR->getOperand(1)->isDefinedOutsideLoopRegions()) {
250250
// Stores to an invariant address only need to store the last part.
251251
remapOperands(&R, UF - 1);
252252
return;

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool vputils::isUniformAcrossVFsAndUFs(VPValue *V) {
9090
return true;
9191

9292
VPRecipeBase *R = V->getDefiningRecipe();
93-
if (R && V->isDefinedOutsideLoop()) {
93+
if (R && V->isDefinedOutsideLoopRegions()) {
9494
if (match(V->getDefiningRecipe(),
9595
m_VPInstruction<VPInstruction::CanonicalIVIncrementForPart>(
9696
m_VPValue())))

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class VPValue {
182182
}
183183

184184
/// Returns true if the VPValue is defined outside any loop.
185-
bool isDefinedOutsideLoop() const;
185+
bool isDefinedOutsideLoopRegions() const;
186186

187187
// Set \p Val as the underlying Value of this VPValue.
188188
void setUnderlyingValue(Value *Val) {

0 commit comments

Comments
 (0)