Skip to content

Commit 6c25bbc

Browse files
committed
!fixup address latest comments, thanks!
1 parent 5adaaed commit 6c25bbc

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,10 +1758,9 @@ VPCostContext::getOperandInfo(VPValue *V) const {
17581758
return TTI::getOperandInfo(V->getLiveInIRValue());
17591759
}
17601760

1761-
InstructionCost
1762-
VPCostContext::getScalarizationOverhead(Type *ResultTy,
1763-
ArrayRef<const VPValue *> Operands,
1764-
ElementCount VF, bool Skip) {
1761+
InstructionCost VPCostContext::getScalarizationOverhead(
1762+
Type *ResultTy, ArrayRef<const VPValue *> Operands, ElementCount VF,
1763+
bool AlwaysIncludeReplicatingR) {
17651764
if (VF.isScalar())
17661765
return 0;
17671766

@@ -1782,9 +1781,8 @@ VPCostContext::getScalarizationOverhead(Type *ResultTy,
17821781
SmallVector<Type *> Tys;
17831782
for (auto *Op : Operands) {
17841783
if (Op->isLiveIn() ||
1785-
(!Skip && isa<VPReplicateRecipe, VPPredInstPHIRecipe>(Op)) ||
1786-
(isa<VPReplicateRecipe>(Op) &&
1787-
cast<VPReplicateRecipe>(Op)->getOpcode() == Instruction::Load) ||
1784+
(!AlwaysIncludeReplicatingR &&
1785+
isa<VPReplicateRecipe, VPPredInstPHIRecipe>(Op)) ||
17881786
!UniqueOperands.insert(Op).second)
17891787
continue;
17901788
Tys.push_back(toVectorizedTy(Types.inferScalarType(Op), VF));

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,7 @@ bool VPReplicateRecipe::shouldPack() const {
30693069
}
30703070

30713071
/// Returns true if \p Ptr is a pointer computation for which the legacy cost
3072-
/// model computes a SCEV expression when comping the address cost.
3072+
/// model computes a SCEV expression when computing the address cost.
30733073
static bool shouldUseAddressAccessSCEV(VPValue *Ptr) {
30743074
auto *PtrR = Ptr->getDefiningRecipe();
30753075
if (!PtrR || !((isa<VPReplicateRecipe>(PtrR) &&
@@ -3078,20 +3078,20 @@ static bool shouldUseAddressAccessSCEV(VPValue *Ptr) {
30783078
isa<VPWidenGEPRecipe>(PtrR)))
30793079
return false;
30803080

3081-
// We are looking for a gep with all loop invariant indices except for one
3081+
// We are looking for a GEP with all loop invariant indices except for one
30823082
// which should be an induction variable.
30833083
unsigned NumOperands = PtrR->getNumOperands();
30843084
for (unsigned Idx = 1; Idx < NumOperands; ++Idx) {
30853085
VPValue *Opd = PtrR->getOperand(Idx);
3086-
if (!(Opd->isDefinedOutsideLoopRegions()) &&
3086+
if (!Opd->isDefinedOutsideLoopRegions() &&
30873087
!isa<VPScalarIVStepsRecipe, VPWidenIntOrFpInductionRecipe>(Opd))
30883088
return false;
30893089
}
30903090

30913091
return true;
30923092
}
30933093

3094-
/// Returns true of \p V is used as part of the address of another load or
3094+
/// Returns true if \p V is used as part of the address of another load or
30953095
/// store.
30963096
static bool isUsedByLoadStoreAddress(const VPUser *V) {
30973097
SmallPtrSet<const VPUser *, 4> Seen;
@@ -3103,7 +3103,7 @@ static bool isUsedByLoadStoreAddress(const VPUser *V) {
31033103
continue;
31043104

31053105
for (VPUser *U : Cur->users()) {
3106-
if (auto *InterleaveR = dyn_cast<VPInterleaveRecipe>(U))
3106+
if (auto *InterleaveR = dyn_cast<VPInterleaveBase>(U))
31073107
if (InterleaveR->getAddr() == Cur)
31083108
return true;
31093109
if (auto *RepR = dyn_cast<VPReplicateRecipe>(U)) {
@@ -3237,7 +3237,8 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
32373237

32383238
// TODO: See getMemInstScalarizationCost for how to handle replicating and
32393239
// predicated cases.
3240-
if (getParent()->getParent() && getParent()->getParent()->isReplicator())
3240+
const VPRegionBlock *ParentRegion = getParent()->getParent();
3241+
if (ParentRegion && ParentRegion->isReplicator())
32413242
break;
32423243

32433244
bool IsLoad = UI->getOpcode() == Instruction::Load;
@@ -3263,18 +3264,20 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
32633264
return ScalarCost;
32643265

32653266
SmallVector<const VPValue *> OpsToScalarize;
3266-
Type *ResultTy = Type::getVoidTy(getParent()->getPlan()->getContext());
3267+
Type *ResultTy = Type::getVoidTy(PtrTy->getContext());
32673268
// Set ResultTy and OpsToScalarize, if scalarization is needed. Currently we
32683269
// don't assign scalarization overhead in general, if the target prefers
32693270
// vectorized addressing or the loaded value is used as part of an address
32703271
// of another load or store.
3271-
if (Ctx.TTI.prefersVectorizedAddressing() ||
3272-
!isUsedByLoadStoreAddress(this)) {
3273-
if (!(IsLoad && !Ctx.TTI.prefersVectorizedAddressing()) &&
3274-
!(!IsLoad && Ctx.TTI.supportsEfficientVectorElementLoadStore()))
3272+
bool PreferVectorizedAddressing = Ctx.TTI.prefersVectorizedAddressing();
3273+
if (PreferVectorizedAddressing || !isUsedByLoadStoreAddress(this)) {
3274+
bool EfficientVectorLoadStore =
3275+
Ctx.TTI.supportsEfficientVectorElementLoadStore();
3276+
if (!(IsLoad && !PreferVectorizedAddressing) &&
3277+
!(!IsLoad && EfficientVectorLoadStore))
32753278
append_range(OpsToScalarize, operands());
32763279

3277-
if (!Ctx.TTI.supportsEfficientVectorElementLoadStore())
3280+
if (!EfficientVectorLoadStore)
32783281
ResultTy = Ctx.Types.inferScalarType(this);
32793282
}
32803283

0 commit comments

Comments
 (0)