Skip to content

Commit 0a369b0

Browse files
authored
Reapply "[MachinePipeliner] Fix constraints aren't considered in cert… (llvm#97259)
…ain cases" (llvm#97246) This reverts commit e6a961d. There is no difference from the original change. I re-ran the failed test and it passed. So the failure wasn't caused by this change. test result: https://lab.llvm.org/buildbot/#/builders/176/builds/585
1 parent 3402a1a commit 0a369b0

File tree

3 files changed

+379
-33
lines changed

3 files changed

+379
-33
lines changed

llvm/include/llvm/CodeGen/MachinePipeliner.h

Lines changed: 5 additions & 2 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,
603-
int *MinEnd, int *MaxStart, int II, SwingSchedulerDAG *DAG);
602+
void computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart, int II,
603+
SwingSchedulerDAG *DAG);
604604
bool insert(SUnit *SU, int StartCycle, int EndCycle, int II);
605605

606606
/// Iterators for the cycle to instruction map.
@@ -658,6 +658,9 @@ 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;
661664
void print(raw_ostream &os) const;
662665
void dump() const;
663666
};

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,47 +2461,43 @@ 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-
// 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);
2464+
Schedule.computeStart(SU, &EarlyStart, &LateStart, II, this);
24702465
LLVM_DEBUG({
24712466
dbgs() << "\n";
24722467
dbgs() << "Inst (" << SU->NodeNum << ") ";
24732468
SU->getInstr()->dump();
24742469
dbgs() << "\n";
24752470
});
2476-
LLVM_DEBUG({
2477-
dbgs() << format("\tes: %8x ls: %8x me: %8x ms: %8x\n", EarlyStart,
2478-
LateStart, SchedEnd, SchedStart);
2479-
});
2471+
LLVM_DEBUG(
2472+
dbgs() << format("\tes: %8x ls: %8x\n", EarlyStart, LateStart));
24802473

2481-
if (EarlyStart > LateStart || SchedEnd < EarlyStart ||
2482-
SchedStart > LateStart)
2474+
if (EarlyStart > LateStart)
24832475
scheduleFound = false;
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);
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);
24982493
else
2499-
scheduleFound = Schedule.insert(SU, EarlyStart, SchedEnd, II);
2494+
scheduleFound = Schedule.insert(SU, EarlyStart, LateStart, II);
25002495
} else {
25012496
int FirstCycle = Schedule.getFirstCycle();
25022497
scheduleFound = Schedule.insert(SU, FirstCycle + getASAP(SU),
25032498
FirstCycle + getASAP(SU) + II - 1, II);
25042499
}
2500+
25052501
// Even if we find a schedule, make sure the schedule doesn't exceed the
25062502
// allowable number of stages. We keep trying if this happens.
25072503
if (scheduleFound)
@@ -2909,8 +2905,7 @@ static SUnit *multipleIterations(SUnit *SU, SwingSchedulerDAG *DAG) {
29092905
/// Compute the scheduling start slot for the instruction. The start slot
29102906
/// depends on any predecessor or successor nodes scheduled already.
29112907
void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
2912-
int *MinEnd, int *MaxStart, int II,
2913-
SwingSchedulerDAG *DAG) {
2908+
int II, SwingSchedulerDAG *DAG) {
29142909
// Iterate over each instruction that has been scheduled already. The start
29152910
// slot computation depends on whether the previously scheduled instruction
29162911
// is a predecessor or successor of the specified instruction.
@@ -2929,7 +2924,7 @@ void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
29292924
*MaxEarlyStart = std::max(*MaxEarlyStart, EarlyStart);
29302925
if (DAG->isLoopCarriedDep(SU, Dep, false)) {
29312926
int End = earliestCycleInChain(Dep) + (II - 1);
2932-
*MinEnd = std::min(*MinEnd, End);
2927+
*MinLateStart = std::min(*MinLateStart, End);
29332928
}
29342929
} else {
29352930
int LateStart = cycle - Dep.getLatency() +
@@ -2953,7 +2948,7 @@ void SMSchedule::computeStart(SUnit *SU, int *MaxEarlyStart, int *MinLateStart,
29532948
*MinLateStart = std::min(*MinLateStart, LateStart);
29542949
if (DAG->isLoopCarriedDep(SU, Dep)) {
29552950
int Start = latestCycleInChain(Dep) + 1 - II;
2956-
*MaxStart = std::max(*MaxStart, Start);
2951+
*MaxEarlyStart = std::max(*MaxEarlyStart, Start);
29572952
}
29582953
} else {
29592954
int EarlyStart = cycle + Dep.getLatency() -
@@ -3146,6 +3141,19 @@ bool SMSchedule::isLoopCarriedDefOfUse(const SwingSchedulerDAG *SSD,
31463141
return false;
31473142
}
31483143

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+
31493157
/// Determine transitive dependences of unpipelineable instructions
31503158
SmallSet<SUnit *, 8> SMSchedule::computeUnpipelineableNodes(
31513159
SwingSchedulerDAG *SSD, TargetInstrInfo::PipelinerLoopInfo *PLI) {

0 commit comments

Comments
 (0)