Skip to content

Commit c709ab9

Browse files
committed
!fixup address latest comments, thanks
1 parent 9361797 commit c709ab9

File tree

7 files changed

+43
-38
lines changed

7 files changed

+43
-38
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ VPRegionBlock *VPRegionBlock::clone() {
775775

776776
if (CanIVInfo.CanIV) {
777777
NewRegion->CanIVInfo.CanIV = new VPRegionValue();
778+
NewRegion->CanIVInfo.Ty = CanIVInfo.Ty;
778779
NewRegion->CanIVInfo.HasNUW = CanIVInfo.HasNUW;
779780
NewRegion->CanIVInfo.DL = CanIVInfo.DL;
780781
}
@@ -901,11 +902,11 @@ void VPRegionBlock::dissolveToCFGLoop() {
901902
Instruction::Add, {CanIV, &Plan.getVFxUF()},
902903
{CanIVInfo.HasNUW, false}, CanIVInfo.DL, "index.next");
903904
}
904-
Type *CanIVTy = VPTypeAnalysis(Plan).inferScalarType(CanIV);
905905
auto *ScalarR =
906906
VPBuilder(Header, Header->begin())
907907
.createScalarPhi(
908-
{Plan.getOrAddLiveIn(ConstantInt::get(CanIVTy, 0)), CanIVInc},
908+
{Plan.getOrAddLiveIn(ConstantInt::get(CanIVInfo.Ty, 0)),
909+
CanIVInc},
909910
CanIVInfo.DL, "index");
910911
CanIV->replaceAllUsesWith(ScalarR);
911912
}
@@ -1555,9 +1556,9 @@ void VPSlotTracker::assignNames(const VPlan &Plan) {
15551556
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<const VPBlockBase *>>
15561557
RPOT(VPBlockDeepTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
15571558
for (const VPBlockBase *VPB : RPOT) {
1558-
if (auto *VPBB = dyn_cast<VPBasicBlock>(VPB)) {
1559+
if (auto *VPBB = dyn_cast<VPBasicBlock>(VPB))
15591560
assignNames(VPBB);
1560-
} else if (auto *CanIV = cast<VPRegionBlock>(VPB)->getCanonicalIV())
1561+
else if (auto *CanIV = cast<VPRegionBlock>(VPB)->getCanonicalIV())
15611562
assignName(CanIV);
15621563
}
15631564
}

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,11 +3900,12 @@ class VPIRBasicBlock : public VPBasicBlock {
39003900
/// Track information about the canonical IV value of a region.
39013901
struct VPCanonicalIVInfo {
39023902
VPRegionValue *CanIV = nullptr;
3903+
Type *Ty = nullptr;
39033904
bool HasNUW = true;
39043905
DebugLoc DL = DebugLoc::getUnknown();
39053906

3906-
VPCanonicalIVInfo(VPRegionValue *CanIV, bool HasNUW, DebugLoc DL)
3907-
: CanIV(CanIV), HasNUW(HasNUW), DL(DL) {}
3907+
VPCanonicalIVInfo(VPRegionValue *CanIV, Type *Ty, bool HasNUW, DebugLoc DL)
3908+
: CanIV(CanIV), Ty(Ty), HasNUW(HasNUW), DL(DL) {}
39083909

39093910
VPCanonicalIVInfo() {}
39103911

@@ -3958,9 +3959,9 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
39583959
Exiting->setParent(this);
39593960
}
39603961

3961-
VPRegionBlock(DebugLoc DL, const std::string &Name = "")
3962+
VPRegionBlock(Type *CanIVTy, DebugLoc DL, const std::string &Name = "")
39623963
: VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3963-
CanIVInfo(new VPRegionValue(), true, DL) {}
3964+
CanIVInfo(new VPRegionValue(), CanIVTy, true, DL) {}
39643965

39653966
public:
39663967
~VPRegionBlock() override {}
@@ -4036,6 +4037,9 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
40364037
VPValue *getCanonicalIV() { return CanIVInfo.CanIV; }
40374038
const VPValue *getCanonicalIV() const { return CanIVInfo.CanIV; }
40384039

4040+
Type *getCanonicalIVType() { return CanIVInfo.Ty; }
4041+
const Type *getCanonicalIVType() const { return CanIVInfo.Ty; }
4042+
40394043
VPCanonicalIVInfo &getCanonicalIVInfo() { return CanIVInfo; }
40404044
};
40414045

@@ -4390,9 +4394,9 @@ class VPlan {
43904394
/// Create a new loop VPRegionBlock with \p StartV and \p Name, and entry and
43914395
/// exiting blocks set to nullptr. The returned block is owned by the VPlan
43924396
/// and deleted once the VPlan is destroyed.
4393-
VPRegionBlock *createVPRegionBlock(DebugLoc DL,
4397+
VPRegionBlock *createVPRegionBlock(Type *CanIVTy, DebugLoc DL,
43944398
const std::string &Name = "") {
4395-
auto *VPB = new VPRegionBlock(DL, Name);
4399+
auto *VPB = new VPRegionBlock(CanIVTy, DL, Name);
43964400
CreatedBlocks.push_back(VPB);
43974401
return VPB;
43984402
}

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ SmallVector<VPRegisterUsage, 8> llvm::calculateRegisterUsageForPlan(
494494
return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
495495
};
496496

497-
if (auto *CanIV = LoopRegion->getCanonicalIV())
498-
if (CanIV->getNumUsers() != 0)
499-
OpenIntervals.insert(CanIV);
497+
VPValue *CanIV = LoopRegion->getCanonicalIV();
498+
if (CanIV->getNumUsers() != 0)
499+
OpenIntervals.insert(CanIV);
500500

501501
// We scan the instructions linearly and record each time that a new interval
502502
// starts, by placing it in a set. If we find this value in TransposEnds then

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ static bool canonicalHeaderAndLatch(VPBlockBase *HeaderVPB,
395395
/// Create a new VPRegionBlock for the loop starting at \p HeaderVPB.
396396
static void createLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB) {
397397
auto *PreheaderVPBB = HeaderVPB->getPredecessors()[0];
398-
auto *LatchVPBB = cast<VPBasicBlock>(HeaderVPB->getPredecessors()[1]);
398+
auto *LatchVPBB = HeaderVPB->getPredecessors()[1];
399399

400400
VPBlockUtils::disconnectBlocks(PreheaderVPBB, HeaderVPB);
401401
VPBlockUtils::disconnectBlocks(LatchVPBB, HeaderVPB);
@@ -409,9 +409,10 @@ static void createLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB) {
409409
VPPhi *ScalarCanIV = nullptr;
410410
if (PreheaderVPBB->getSinglePredecessor() == Plan.getEntry())
411411
ScalarCanIV = cast<VPPhi>(&*cast<VPBasicBlock>(HeaderVPB)->begin());
412-
auto *R =
413-
Plan.createVPRegionBlock(ScalarCanIV ? ScalarCanIV->getDebugLoc()
414-
: DebugLoc::getCompilerGenerated());
412+
auto *R = Plan.createVPRegionBlock(
413+
ScalarCanIV->getOperand(0)->getLiveInIRValue()->getType(),
414+
ScalarCanIV ? ScalarCanIV->getDebugLoc()
415+
: DebugLoc::getCompilerGenerated());
415416
VPBlockUtils::insertOnEdge(LatchVPBB, LatchExitVPB, R);
416417
VPBlockUtils::disconnectBlocks(LatchVPBB, R);
417418
VPBlockUtils::connectBlocks(PreheaderVPBB, R);
@@ -447,7 +448,10 @@ static void addCanonicalIVRecipes(VPlan &Plan, VPBasicBlock *HeaderVPBB,
447448
}
448449

449450
VPBuilder Builder(LatchVPBB);
450-
auto CanonicalIVIncrement = Builder.createOverflowingOp(
451+
// Add a VPInstruction to increment the scalar canonical IV by VF * UF.
452+
// Initially the induction increment is guaranteed to not wrap, but that may
453+
// change later, e.g. when tail-folding, when the flags need to be dropped.
454+
auto *CanonicalIVIncrement = Builder.createOverflowingOp(
451455
Instruction::Add, {CanonicalIVPHI, &Plan.getVFxUF()}, {true, false}, DL,
452456
"index.next");
453457
// Add the BranchOnCount VPInstruction to the latch.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,11 +2341,9 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
23412341
if (getStepValue()->getDefiningRecipe())
23422342
return false;
23432343
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
2344-
auto *CanIV = getParent()->getParent()->getCanonicalIV();
23452344
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
23462345
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
2347-
getScalarType() ==
2348-
VPTypeAnalysis(*getParent()->getPlan()).inferScalarType(CanIV);
2346+
getScalarType() == getParent()->getParent()->getCanonicalIVType();
23492347
}
23502348

23512349
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,9 +1710,8 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF,
17101710
HeaderR.getVPSingleValue()->replaceAllUsesWith(Phi->getIncomingValue(0));
17111711
HeaderR.eraseFromParent();
17121712
}
1713-
Plan.getCanonicalIV()->replaceAllUsesWith(
1714-
Plan.getOrAddLiveIn(ConstantInt::getNullValue(
1715-
VPTypeAnalysis(Plan).inferScalarType(Plan.getCanonicalIV()))));
1713+
VectorRegion->getCanonicalIV()->replaceAllUsesWith(Plan.getOrAddLiveIn(
1714+
ConstantInt::getNullValue(VectorRegion->getCanonicalIVType())));
17161715

17171716
VPBlockBase *Preheader = VectorRegion->getSinglePredecessor();
17181717
VPBlockBase *Exit = VectorRegion->getSingleSuccessor();
@@ -2319,16 +2318,15 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23192318
VPlan &Plan, bool DataAndControlFlowWithoutRuntimeCheck) {
23202319
VPRegionBlock *TopRegion = Plan.getVectorLoopRegion();
23212320
VPBasicBlock *EB = TopRegion->getExitingBasicBlock();
2322-
VPValue *CanonicalIV = Plan.getCanonicalIV();
2323-
VPValue *StartV = Plan.getOrAddLiveIn(Constant::getNullValue(
2324-
VPTypeAnalysis(Plan).inferScalarType(CanonicalIV)));
2321+
auto &CanIVInfo = Plan.getCanonicalIVInfo();
2322+
VPValue *CanonicalIV = CanIVInfo.CanIV;
2323+
VPValue *StartV = Plan.getOrAddLiveIn(Constant::getNullValue(CanIVInfo.Ty));
23252324

23262325
auto *CanonicalIVIncrement =
23272326
cast<VPInstruction>(EB->getTerminator()->getOperand(0));
23282327
// TODO: Check if dropping the flags is needed if
23292328
// !DataAndControlFlowWithoutRuntimeCheck.
23302329
CanonicalIVIncrement->dropPoisonGeneratingFlags();
2331-
auto &CanIVInfo = Plan.getCanonicalIVInfo();
23322330
CanIVInfo.HasNUW = false;
23332331
DebugLoc DL = CanIVInfo.DL;
23342332
// We can't use StartV directly in the ActiveLaneMask VPInstruction, since
@@ -2360,8 +2358,8 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23602358
"index.part.next");
23612359

23622360
// Create the active lane mask instruction in the VPlan preheader.
2363-
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2364-
ConstantInt::get(VPTypeAnalysis(Plan).inferScalarType(CanonicalIV), 1));
2361+
VPValue *ALMMultiplier =
2362+
Plan.getOrAddLiveIn(ConstantInt::get(CanIVInfo.Ty, 1));
23652363
auto *EntryALM = Builder.createNaryOp(VPInstruction::ActiveLaneMask,
23662364
{EntryIncrement, TC, ALMMultiplier}, DL,
23672365
"active.lane.mask.entry");
@@ -2458,8 +2456,8 @@ void VPlanTransforms::addActiveLaneMask(
24582456
Plan, DataAndControlFlowWithoutRuntimeCheck);
24592457
} else {
24602458
VPBuilder B = VPBuilder::getToInsertAfter(WideCanonicalIV);
2461-
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(ConstantInt::get(
2462-
VPTypeAnalysis(Plan).inferScalarType(Plan.getCanonicalIV()), 1));
2459+
VPValue *ALMMultiplier =
2460+
Plan.getOrAddLiveIn(ConstantInt::get(Plan.getCanonicalIVInfo().Ty, 1));
24632461
LaneMask =
24642462
B.createNaryOp(VPInstruction::ActiveLaneMask,
24652463
{WideCanonicalIV, Plan.getTripCount(), ALMMultiplier},
@@ -2730,7 +2728,7 @@ void VPlanTransforms::addExplicitVectorLength(
27302728

27312729
auto *CanonicalIV = Plan.getCanonicalIV();
27322730
auto &CanIVInfo = Plan.getCanonicalIVInfo();
2733-
auto *CanIVTy = VPTypeAnalysis(Plan).inferScalarType(CanonicalIV);
2731+
auto *CanIVTy = CanIVInfo.Ty;
27342732
VPValue *StartV = Plan.getOrAddLiveIn(ConstantInt::getNullValue(CanIVTy));
27352733
auto *CanonicalIVIncrement = cast<VPInstruction>(Plan.getVectorLoopRegion()
27362734
->getExitingBasicBlock()
@@ -4174,8 +4172,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
41744172

41754173
// Adjust induction to reflect that the transformed plan only processes one
41764174
// original iteration.
4177-
auto *CanIV = Plan.getCanonicalIV();
4178-
Type *CanIVTy = TypeInfo.inferScalarType(CanIV);
4175+
Type *CanIVTy = Plan.getCanonicalIVInfo().Ty;
41794176
auto *Inc = cast<VPInstruction>(
41804177
VectorLoop->getExitingBasicBlock()->getTerminator()->getOperand(0));
41814178
VPBuilder PHBuilder(Plan.getVectorPreheader());

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ class LLVM_ABI_FOR_TEST VPValue {
169169
const VPRecipeBase *getDefiningRecipe() const;
170170

171171
/// Returns true if this VPValue is defined by a recipe.
172-
bool hasDefiningRecipe() const { return getDefiningRecipe(); }
172+
bool hasDefiningRecipe() const {
173+
return SubclassID != VPRegionValueSC && getDefiningRecipe();
174+
}
173175

174176
/// Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
175177
bool isLiveIn() const {
@@ -196,8 +198,7 @@ class LLVM_ABI_FOR_TEST VPValue {
196198
};
197199

198200
/// VPValues defined by a VPRegionBlock, like the canonical IV.
199-
class VPRegionValue : public VPValue {
200-
public:
201+
struct VPRegionValue : public VPValue {
201202
VPRegionValue() : VPValue(VPValue::VPRegionValueSC) {}
202203

203204
~VPRegionValue() override = default;

0 commit comments

Comments
 (0)