Skip to content

Commit 9317975

Browse files
committed
[VPlan] Match legacy behavior w.r.t. using pointer phis as scalar addrs.
When the legacy cost model scalarizes loads that are used as addresses for other loads and stores, it looks to phi nodes, if they are direct address operands of loads/stores. Match this behavior in isUsedByLoadStoreAddress, to fix a divergence between legacy and VPlan-based cost model.
1 parent c1852af commit 9317975

File tree

2 files changed

+396
-2
lines changed

2 files changed

+396
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,17 @@ static bool isUsedByLoadStoreAddress(const VPUser *V) {
31623162

31633163
while (!WorkList.empty()) {
31643164
auto *Cur = dyn_cast<VPSingleDefRecipe>(WorkList.pop_back_val());
3165-
if (!Cur || !Seen.insert(Cur).second || isa<VPBlendRecipe>(Cur))
3165+
if (!Cur || !Seen.insert(Cur).second)
3166+
continue;
3167+
3168+
auto *Blend = dyn_cast<VPBlendRecipe>(Cur);
3169+
// Skip blends that use V only through a compare by checking if any incoming
3170+
// value was already visited.
3171+
if (Blend && none_of(seq<unsigned>(0, Blend->getNumIncomingValues()),
3172+
[&](unsigned I) {
3173+
return Seen.contains(
3174+
Blend->getIncomingValue(I)->getDefiningRecipe());
3175+
}))
31663176
continue;
31673177

31683178
for (VPUser *U : Cur->users()) {
@@ -3183,7 +3193,13 @@ static bool isUsedByLoadStoreAddress(const VPUser *V) {
31833193
}
31843194
}
31853195

3186-
append_range(WorkList, cast<VPSingleDefRecipe>(Cur)->users());
3196+
// The legacy cost model only supports scalarization loads/stores with phi
3197+
// addresses, if the phi is directly used as load/store address. Don't
3198+
// traverse further for Blends.
3199+
if (Blend)
3200+
continue;
3201+
3202+
append_range(WorkList, Cur->users());
31873203
}
31883204
return false;
31893205
}

0 commit comments

Comments
 (0)