diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c614fd31a3b00..4bf6b4bef6aab 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2624,6 +2624,9 @@ class BoUpSLP { /// the current SchedulingRegionID of BlockScheduling. int SchedulingRegionID = 0; + /// Used for getting a "good" final ordering of instructions. + int SchedulingPriority = 0; + /// The number of dependencies. Constitutes of the number of users of the /// instruction plus the number of dependent memory instructions (if any). /// This value is calculated on demand. @@ -7982,23 +7985,23 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) { // For the real scheduling we use a more sophisticated ready-list: it is // sorted by the original instruction location. This lets the final schedule // be as close as possible to the original instruction order. - DenseMap OriginalOrder; - auto ScheduleDataCompare = [&](ScheduleData *SD1, ScheduleData *SD2) { - return OriginalOrder[SD2] < OriginalOrder[SD1]; + struct ScheduleDataCompare { + bool operator()(ScheduleData *SD1, ScheduleData *SD2) const { + return SD2->SchedulingPriority < SD1->SchedulingPriority; + } }; - std::set - ReadyInsts(ScheduleDataCompare); + std::set ReadyInsts; // Ensure that all dependency data is updated (for nodes in the sub-graph) // and fill the ready-list with initial instructions. int Idx = 0; for (auto *I = BS->ScheduleStart; I != BS->ScheduleEnd; I = I->getNextNode()) { - BS->doForAllOpcodes(I, [&](ScheduleData *SD) { + BS->doForAllOpcodes(I, [this, &Idx, BS](ScheduleData *SD) { assert((isVectorLikeInstWithConstOps(SD->Inst) || SD->isPartOfBundle() == (getTreeEntry(SD->Inst) != nullptr)) && "scheduler and vectorizer bundle mismatch"); - OriginalOrder[SD->FirstInBundle] = Idx++; + SD->FirstInBundle->SchedulingPriority = Idx++; if (SD->isSchedulingEntity() && SD->isPartOfBundle()) BS->calculateDependencies(SD, false, this);