@@ -5291,19 +5291,19 @@ class BoUpSLP {
52915291 // data.
52925292 for (TreeEntry *TE : Entries) {
52935293 // Check if the user is commutative.
5294- // The commutatives are handled later, as their oeprands can be
5294+ // The commutatives are handled later, as their operands can be
52955295 // reordered.
52965296 // Same applies even for non-commutative cmps, because we can invert
52975297 // their predicate potentially and, thus, reorder the operands.
52985298 bool IsCommutativeUser =
52995299 ::isCommutative(User) ||
53005300 ::isCommutative(TE->getMatchingMainOpOrAltOp(User), User);
5301- EdgeInfo EI(TE, U.getOperandNo());
53025301 if (!IsCommutativeUser && !isa<CmpInst>(User)) {
53035302 unsigned &OpCnt =
53045303 OrderedEntriesCount.try_emplace(TE, 0).first->getSecond();
5304+ EdgeInfo EI(TE, U.getOperandNo());
53055305 if (!getScheduleCopyableData(EI, Op) && OpCnt < NumOps)
5306- return false ;
5306+ continue ;
53075307 // Found copyable operand - continue.
53085308 ++OpCnt;
53095309 continue;
@@ -5312,33 +5312,38 @@ class BoUpSLP {
53125312 .first->getSecond();
53135313 }
53145314 }
5315- // Check the commutative/cmp entries.
5316- if (!PotentiallyReorderedEntriesCount.empty()) {
5317- for (auto &P : PotentiallyReorderedEntriesCount) {
5318- auto *It = find(P.first->Scalars, User);
5319- assert(It != P.first->Scalars.end() &&
5320- "User is not in the tree entry");
5321- int Lane = std::distance(P.first->Scalars.begin(), It);
5322- assert(Lane >= 0 && "Lane is not found");
5323- if (isa<StoreInst>(User) && !P.first->ReorderIndices.empty())
5324- Lane = P.first->ReorderIndices[Lane];
5325- assert(Lane < static_cast<int>(P.first->Scalars.size()) &&
5326- "Couldn't find extract lane");
5327- SmallVector<unsigned> OpIndices;
5328- for (unsigned OpIdx :
5329- seq<unsigned>(::getNumberOfPotentiallyCommutativeOps(
5330- P.first->getMainOp()))) {
5331- if (P.first->getOperand(OpIdx)[Lane] == Op &&
5332- getScheduleCopyableData(EdgeInfo(P.first, OpIdx), Op))
5333- --P.getSecond();
5334- }
5335- }
5336- return all_of(PotentiallyReorderedEntriesCount,
5315+ if (PotentiallyReorderedEntriesCount.empty())
5316+ return all_of(OrderedEntriesCount,
53375317 [&](const std::pair<const TreeEntry *, unsigned> &P) {
5338- return P.second == NumOps - 1 ;
5318+ return P.second == NumOps;
53395319 });
5340- }
5341- return true;
5320+ // Check the commutative/cmp entries.
5321+ for (auto &P : PotentiallyReorderedEntriesCount) {
5322+ auto *It = find(P.first->Scalars, User);
5323+ assert(It != P.first->Scalars.end() && "User is not in the tree entry");
5324+ int Lane = std::distance(P.first->Scalars.begin(), It);
5325+ assert(Lane >= 0 && "Lane is not found");
5326+ if (isa<StoreInst>(User) && !P.first->ReorderIndices.empty())
5327+ Lane = P.first->ReorderIndices[Lane];
5328+ assert(Lane < static_cast<int>(P.first->Scalars.size()) &&
5329+ "Couldn't find extract lane");
5330+ SmallVector<unsigned> OpIndices;
5331+ for (unsigned OpIdx :
5332+ seq<unsigned>(::getNumberOfPotentiallyCommutativeOps(
5333+ P.first->getMainOp()))) {
5334+ if (P.first->getOperand(OpIdx)[Lane] == Op &&
5335+ getScheduleCopyableData(EdgeInfo(P.first, OpIdx), Op))
5336+ --P.getSecond();
5337+ }
5338+ }
5339+ return all_of(PotentiallyReorderedEntriesCount,
5340+ [&](const std::pair<const TreeEntry *, unsigned> &P) {
5341+ return P.second == NumOps - 1;
5342+ }) &&
5343+ all_of(OrderedEntriesCount,
5344+ [&](const std::pair<const TreeEntry *, unsigned> &P) {
5345+ return P.second == NumOps;
5346+ });
53425347 }
53435348
53445349 SmallVector<ScheduleCopyableData *>
0 commit comments