Skip to content

Commit f28c4b4

Browse files
[SLP]Fix/improve potential masked gather loads analysis.
When do the analysis for the (potential) masked gather node, we check that not greater than half of the pointer operands are loop invariants or potentially vectorizable. Need to check actually, that we have a loop at first and do better check for the potentially vectorizable pointers. Reviewers: RKSimon Reviewed By: RKSimon Pull Request: #83472
1 parent 7ac03e8 commit f28c4b4

File tree

3 files changed

+355
-346
lines changed

3 files changed

+355
-346
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,14 +4100,14 @@ static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
41004100
// increases the cost.
41014101
Loop *L = LI.getLoopFor(cast<LoadInst>(VL0)->getParent());
41024102
bool ProfitableGatherPointers =
4103-
static_cast<unsigned>(count_if(
4104-
PointerOps,
4105-
[L](Value *V) { return L && L->isLoopInvariant(V); })) <= Sz / 2 &&
4106-
Sz > 2;
4103+
L && Sz > 2 && count_if(PointerOps, [L](Value *V) {
4104+
return L->isLoopInvariant(V);
4105+
}) <= Sz / 2;
41074106
if (ProfitableGatherPointers || all_of(PointerOps, [IsSorted](Value *P) {
41084107
auto *GEP = dyn_cast<GetElementPtrInst>(P);
41094108
return (IsSorted && !GEP && doesNotNeedToBeScheduled(P)) ||
4110-
(GEP && GEP->getNumOperands() == 2);
4109+
(GEP && GEP->getNumOperands() == 2 &&
4110+
isa<Constant, Instruction>(GEP->getOperand(1)));
41114111
})) {
41124112
Align CommonAlignment = computeCommonAlignment<LoadInst>(VL);
41134113
if (TTI.isLegalMaskedGather(VecTy, CommonAlignment) &&

0 commit comments

Comments
 (0)