Skip to content

Commit e6a961d

Browse files
authored
Revert "[MachinePipeliner] Fix constraints aren't considered in certain cases" (llvm#97246)
Reverts llvm#95356 Due to ppc64le test failures caught by the LLVM Buildbot. https://lab.llvm.org/buildbot/#/builders/176/builds/576
1 parent 1d4ce57 commit e6a961d

File tree

3 files changed

+33
-379
lines changed

3 files changed

+33
-379
lines changed

llvm/include/llvm/CodeGen/MachinePipeliner.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ class SMSchedule {
599599
/// chain.
600600
int latestCycleInChain(const SDep &Dep);
601601

602-
void computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart, int II,
603-
SwingSchedulerDAG *DAG);
602+
void computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
603+
int *MinEnd, int *MaxStart, int II, SwingSchedulerDAG *DAG);
604604
bool insert(SUnit *SU, int StartCycle, int EndCycle, int II);
605605

606606
/// Iterators for the cycle to instruction map.
@@ -658,9 +658,6 @@ class SMSchedule {
658658
bool isLoopCarried(const SwingSchedulerDAG *SSD, MachineInstr &Phi) const;
659659
bool isLoopCarriedDefOfUse(const SwingSchedulerDAG *SSD, MachineInstr *Def,
660660
MachineOperand &MO) const;
661-
662-
bool onlyHasLoopCarriedOutputOrOrderPreds(SUnit *SU,
663-
SwingSchedulerDAG *DAG) const;
664661
void print(raw_ostream &os) const;
665662
void dump() const;
666663
};

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,43 +2461,47 @@ bool SwingSchedulerDAG::schedulePipeline(SMSchedule &Schedule) {
24612461
// upon the scheduled time for any predecessors/successors.
24622462
int EarlyStart = INT_MIN;
24632463
int LateStart = INT_MAX;
2464-
Schedule.computeStart(SU, &EarlyStart, &LateStart, II, this);
2464+
// These values are set when the size of the schedule window is limited
2465+
// due to chain dependences.
2466+
int SchedEnd = INT_MAX;
2467+
int SchedStart = INT_MIN;
2468+
Schedule.computeStart(SU, &EarlyStart, &LateStart, &SchedEnd, &SchedStart,
2469+
II, this);
24652470
LLVM_DEBUG({
24662471
dbgs() << "\n";
24672472
dbgs() << "Inst (" << SU->NodeNum << ") ";
24682473
SU->getInstr()->dump();
24692474
dbgs() << "\n";
24702475
});
2471-
LLVM_DEBUG(
2472-
dbgs() << format("\tes: %8x ls: %8x\n", EarlyStart, LateStart));
2476+
LLVM_DEBUG({
2477+
dbgs() << format("\tes: %8x ls: %8x me: %8x ms: %8x\n", EarlyStart,
2478+
LateStart, SchedEnd, SchedStart);
2479+
});
24732480

2474-
if (EarlyStart > LateStart)
2481+
if (EarlyStart > LateStart || SchedEnd < EarlyStart ||
2482+
SchedStart > LateStart)
24752483
scheduleFound = false;
2476-
else if (EarlyStart != INT_MIN && LateStart == INT_MAX)
2477-
scheduleFound =
2478-
Schedule.insert(SU, EarlyStart, EarlyStart + (int)II - 1, II);
2479-
else if (EarlyStart == INT_MIN && LateStart != INT_MAX)
2480-
scheduleFound =
2481-
Schedule.insert(SU, LateStart, LateStart - (int)II + 1, II);
2482-
else if (EarlyStart != INT_MIN && LateStart != INT_MAX) {
2483-
LateStart = std::min(LateStart, EarlyStart + (int)II - 1);
2484-
// When scheduling a Phi it is better to start at the late cycle and
2485-
// go backwards. The default order may insert the Phi too far away
2486-
// from its first dependence.
2487-
// Also, do backward search when all scheduled predecessors are
2488-
// loop-carried output/order dependencies. Empirically, there are also
2489-
// cases where scheduling becomes possible with backward search.
2490-
if (SU->getInstr()->isPHI() ||
2491-
Schedule.onlyHasLoopCarriedOutputOrOrderPreds(SU, this))
2492-
scheduleFound = Schedule.insert(SU, LateStart, EarlyStart, II);
2484+
else if (EarlyStart != INT_MIN && LateStart == INT_MAX) {
2485+
SchedEnd = std::min(SchedEnd, EarlyStart + (int)II - 1);
2486+
scheduleFound = Schedule.insert(SU, EarlyStart, SchedEnd, II);
2487+
} else if (EarlyStart == INT_MIN && LateStart != INT_MAX) {
2488+
SchedStart = std::max(SchedStart, LateStart - (int)II + 1);
2489+
scheduleFound = Schedule.insert(SU, LateStart, SchedStart, II);
2490+
} else if (EarlyStart != INT_MIN && LateStart != INT_MAX) {
2491+
SchedEnd =
2492+
std::min(SchedEnd, std::min(LateStart, EarlyStart + (int)II - 1));
2493+
// When scheduling a Phi it is better to start at the late cycle and go
2494+
// backwards. The default order may insert the Phi too far away from
2495+
// its first dependence.
2496+
if (SU->getInstr()->isPHI())
2497+
scheduleFound = Schedule.insert(SU, SchedEnd, EarlyStart, II);
24932498
else
2494-
scheduleFound = Schedule.insert(SU, EarlyStart, LateStart, II);
2499+
scheduleFound = Schedule.insert(SU, EarlyStart, SchedEnd, II);
24952500
} else {
24962501
int FirstCycle = Schedule.getFirstCycle();
24972502
scheduleFound = Schedule.insert(SU, FirstCycle + getASAP(SU),
24982503
FirstCycle + getASAP(SU) + II - 1, II);
24992504
}
2500-
25012505
// Even if we find a schedule, make sure the schedule doesn't exceed the
25022506
// allowable number of stages. We keep trying if this happens.
25032507
if (scheduleFound)
@@ -2905,7 +2909,8 @@ static SUnit *multipleIterations(SUnit *SU, SwingSchedulerDAG *DAG) {
29052909
/// Compute the scheduling start slot for the instruction. The start slot
29062910
/// depends on any predecessor or successor nodes scheduled already.
29072911
void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
2908-
int II, SwingSchedulerDAG *DAG) {
2912+
int *MinEnd, int *MaxStart, int II,
2913+
SwingSchedulerDAG *DAG) {
29092914
// Iterate over each instruction that has been scheduled already. The start
29102915
// slot computation depends on whether the previously scheduled instruction
29112916
// is a predecessor or successor of the specified instruction.
@@ -2924,7 +2929,7 @@ void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
29242929
*MaxEarlyStart = std::max(*MaxEarlyStart, EarlyStart);
29252930
if (DAG->isLoopCarriedDep(SU, Dep, false)) {
29262931
int End = earliestCycleInChain(Dep) + (II - 1);
2927-
*MinLateStart = std::min(*MinLateStart, End);
2932+
*MinEnd = std::min(*MinEnd, End);
29282933
}
29292934
} else {
29302935
int LateStart = cycle - Dep.getLatency() +
@@ -2948,7 +2953,7 @@ void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
29482953
*MinLateStart = std::min(*MinLateStart, LateStart);
29492954
if (DAG->isLoopCarriedDep(SU, Dep)) {
29502955
int Start = latestCycleInChain(Dep) + 1 - II;
2951-
*MaxEarlyStart = std::max(*MaxEarlyStart, Start);
2956+
*MaxStart = std::max(*MaxStart, Start);
29522957
}
29532958
} else {
29542959
int EarlyStart = cycle + Dep.getLatency() -
@@ -3141,19 +3146,6 @@ bool SMSchedule::isLoopCarriedDefOfUse(const SwingSchedulerDAG *SSD,
31413146
return false;
31423147
}
31433148

3144-
/// Return true if all scheduled predecessors are loop-carried output/order
3145-
/// dependencies.
3146-
bool SMSchedule::onlyHasLoopCarriedOutputOrOrderPreds(
3147-
SUnit *SU, SwingSchedulerDAG *DAG) const {
3148-
for (const SDep &Pred : SU->Preds)
3149-
if (InstrToCycle.count(Pred.getSUnit()) && !DAG->isBackedge(SU, Pred))
3150-
return false;
3151-
for (const SDep &Succ : SU->Succs)
3152-
if (InstrToCycle.count(Succ.getSUnit()) && DAG->isBackedge(SU, Succ))
3153-
return false;
3154-
return true;
3155-
}
3156-
31573149
/// Determine transitive dependences of unpipelineable instructions
31583150
SmallSet<SUnit *, 8> SMSchedule::computeUnpipelineableNodes(
31593151
SwingSchedulerDAG *SSD, TargetInstrInfo::PipelinerLoopInfo *PLI) {

0 commit comments

Comments
 (0)