Skip to content

Commit 631adc9

Browse files
JonPssonJonPsson1
authored andcommitted
REBASED
Final cleanup. MISched0, with -misched-gprloads. Simplified and refined. Remove previous versions. -tiny-region Disable pre-ra scheduling. Revert "Disable pre-ra scheduling." Try TinyRegion=10 without extra checks. Revert "Try TinyRegion=10 without extra checks." Try TinyRegion=10 with some exclusions. Tiny10Lat without chainpreds and hazard Was c0f4354
1 parent 2c31403 commit 631adc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2860
-996
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
10871087
NoCand,
10881088
Only1,
10891089
PhysReg,
1090+
LivenessReduce,
10901091
RegExcess,
10911092
RegCritical,
10921093
Stall,
@@ -1218,6 +1219,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
12181219
};
12191220

12201221
// Utility functions used by heuristics in tryCandidate().
1222+
unsigned computeRemLatency(SchedBoundary &CurrZone);
12211223
bool tryLess(int TryVal, int CandVal,
12221224
GenericSchedulerBase::SchedCandidate &TryCand,
12231225
GenericSchedulerBase::SchedCandidate &Cand,

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,31 +3168,6 @@ initResourceDelta(const ScheduleDAGMI *DAG,
31683168
}
31693169
}
31703170

3171-
/// Compute remaining latency. We need this both to determine whether the
3172-
/// overall schedule has become latency-limited and whether the instructions
3173-
/// outside this zone are resource or latency limited.
3174-
///
3175-
/// The "dependent" latency is updated incrementally during scheduling as the
3176-
/// max height/depth of scheduled nodes minus the cycles since it was
3177-
/// scheduled:
3178-
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
3179-
///
3180-
/// The "independent" latency is the max ready queue depth:
3181-
/// ILat = max N.depth for N in Available|Pending
3182-
///
3183-
/// RemainingLatency is the greater of independent and dependent latency.
3184-
///
3185-
/// These computations are expensive, especially in DAGs with many edges, so
3186-
/// only do them if necessary.
3187-
static unsigned computeRemLatency(SchedBoundary &CurrZone) {
3188-
unsigned RemLatency = CurrZone.getDependentLatency();
3189-
RemLatency = std::max(RemLatency,
3190-
CurrZone.findMaxLatency(CurrZone.Available.elements()));
3191-
RemLatency = std::max(RemLatency,
3192-
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
3193-
return RemLatency;
3194-
}
3195-
31963171
/// Returns true if the current cycle plus remaning latency is greater than
31973172
/// the critical path in the scheduling region.
31983173
bool GenericSchedulerBase::shouldReduceLatency(const CandPolicy &Policy,
@@ -3278,6 +3253,7 @@ const char *GenericSchedulerBase::getReasonStr(
32783253
case NoCand: return "NOCAND ";
32793254
case Only1: return "ONLY1 ";
32803255
case PhysReg: return "PHYS-REG ";
3256+
case LivenessReduce: return "LIVE-REDUC";
32813257
case RegExcess: return "REG-EXCESS";
32823258
case RegCritical: return "REG-CRIT ";
32833259
case Stall: return "STALL ";
@@ -3351,6 +3327,31 @@ void GenericSchedulerBase::traceCandidate(const SchedCandidate &Cand) {
33513327
#endif
33523328

33533329
namespace llvm {
3330+
/// Compute remaining latency. We need this both to determine whether the
3331+
/// overall schedule has become latency-limited and whether the instructions
3332+
/// outside this zone are resource or latency limited.
3333+
///
3334+
/// The "dependent" latency is updated incrementally during scheduling as the
3335+
/// max height/depth of scheduled nodes minus the cycles since it was
3336+
/// scheduled:
3337+
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
3338+
///
3339+
/// The "independent" latency is the max ready queue depth:
3340+
/// ILat = max N.depth for N in Available|Pending
3341+
///
3342+
/// RemainingLatency is the greater of independent and dependent latency.
3343+
///
3344+
/// These computations are expensive, especially in DAGs with many edges, so
3345+
/// only do them if necessary.
3346+
unsigned computeRemLatency(SchedBoundary &CurrZone) {
3347+
unsigned RemLatency = CurrZone.getDependentLatency();
3348+
RemLatency = std::max(RemLatency,
3349+
CurrZone.findMaxLatency(CurrZone.Available.elements()));
3350+
RemLatency = std::max(RemLatency,
3351+
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
3352+
return RemLatency;
3353+
}
3354+
33543355
/// Return true if this heuristic determines order.
33553356
/// TODO: Consider refactor return type of these functions as integer or enum,
33563357
/// as we may need to differentiate whether TryCand is better than Cand.

llvm/lib/Target/SystemZ/SystemZElimCompare.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,6 @@ Reference SystemZElimCompare::getRegReferences(MachineInstr &MI, unsigned Reg) {
151151
return Ref;
152152
}
153153

154-
// Return true if this is a load and test which can be optimized the
155-
// same way as compare instruction.
156-
static bool isLoadAndTestAsCmp(MachineInstr &MI) {
157-
// If we during isel used a load-and-test as a compare with 0, the
158-
// def operand is dead.
159-
return (MI.getOpcode() == SystemZ::LTEBR ||
160-
MI.getOpcode() == SystemZ::LTDBR ||
161-
MI.getOpcode() == SystemZ::LTXBR) &&
162-
MI.getOperand(0).isDead();
163-
}
164-
165-
// Return the source register of Compare, which is the unknown value
166-
// being tested.
167-
static unsigned getCompareSourceReg(MachineInstr &Compare) {
168-
unsigned reg = 0;
169-
if (Compare.isCompare())
170-
reg = Compare.getOperand(0).getReg();
171-
else if (isLoadAndTestAsCmp(Compare))
172-
reg = Compare.getOperand(1).getReg();
173-
assert(reg);
174-
175-
return reg;
176-
}
177-
178154
// Compare compares the result of MI against zero. If MI is an addition
179155
// of -1 and if CCUsers is a single branch on nonzero, eliminate the addition
180156
// and convert the branch to a BRCT(G) or BRCTH. Return true on success.
@@ -207,7 +183,7 @@ bool SystemZElimCompare::convertToBRCT(
207183
// We already know that there are no references to the register between
208184
// MI and Compare. Make sure that there are also no references between
209185
// Compare and Branch.
210-
unsigned SrcReg = getCompareSourceReg(Compare);
186+
unsigned SrcReg = TII->getCompareSourceReg(Compare);
211187
MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch;
212188
for (++MBBI; MBBI != MBBE; ++MBBI)
213189
if (getRegReferences(*MBBI, SrcReg))
@@ -254,7 +230,7 @@ bool SystemZElimCompare::convertToLoadAndTrap(
254230
// We already know that there are no references to the register between
255231
// MI and Compare. Make sure that there are also no references between
256232
// Compare and Branch.
257-
unsigned SrcReg = getCompareSourceReg(Compare);
233+
unsigned SrcReg = TII->getCompareSourceReg(Compare);
258234
MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch;
259235
for (++MBBI; MBBI != MBBE; ++MBBI)
260236
if (getRegReferences(*MBBI, SrcReg))
@@ -495,25 +471,17 @@ bool SystemZElimCompare::adjustCCMasksForInstr(
495471
return true;
496472
}
497473

498-
// Return true if Compare is a comparison against zero.
499-
static bool isCompareZero(MachineInstr &Compare) {
500-
if (isLoadAndTestAsCmp(Compare))
501-
return true;
502-
return Compare.getNumExplicitOperands() == 2 &&
503-
Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
504-
}
505-
506474
// Try to optimize cases where comparison instruction Compare is testing
507475
// a value against zero. Return true on success and if Compare should be
508476
// deleted as dead. CCUsers is the list of instructions that use the CC
509477
// value produced by Compare.
510478
bool SystemZElimCompare::optimizeCompareZero(
511479
MachineInstr &Compare, SmallVectorImpl<MachineInstr *> &CCUsers) {
512-
if (!isCompareZero(Compare))
480+
if (!TII->isCompareZero(Compare))
513481
return false;
514482

515483
// Search back for CC results that are based on the first operand.
516-
unsigned SrcReg = getCompareSourceReg(Compare);
484+
unsigned SrcReg = TII->getCompareSourceReg(Compare);
517485
MachineBasicBlock &MBB = *Compare.getParent();
518486
Reference CCRefs;
519487
Reference SrcRefs;
@@ -702,7 +670,7 @@ bool SystemZElimCompare::processBlock(MachineBasicBlock &MBB) {
702670
MachineBasicBlock::iterator MBBI = MBB.end();
703671
while (MBBI != MBB.begin()) {
704672
MachineInstr &MI = *--MBBI;
705-
if (CompleteCCUsers && (MI.isCompare() || isLoadAndTestAsCmp(MI)) &&
673+
if (CompleteCCUsers && (MI.isCompare() || TII->isLoadAndTestAsCmp(MI)) &&
706674
(optimizeCompareZero(MI, CCUsers) ||
707675
fuseCompareOperations(MI, CCUsers))) {
708676
++MBBI;

llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,34 @@ unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode,
21442144
return 0;
21452145
}
21462146

2147+
bool SystemZInstrInfo::isLoadAndTestAsCmp(const MachineInstr &MI) const {
2148+
// If we during isel used a load-and-test as a compare with 0, the
2149+
// def operand is dead.
2150+
return (MI.getOpcode() == SystemZ::LTEBR ||
2151+
MI.getOpcode() == SystemZ::LTDBR ||
2152+
MI.getOpcode() == SystemZ::LTXBR) &&
2153+
MI.getOperand(0).isDead();
2154+
}
2155+
2156+
bool SystemZInstrInfo::isCompareZero(const MachineInstr &Compare) const {
2157+
if (isLoadAndTestAsCmp(Compare))
2158+
return true;
2159+
return Compare.isCompare() && Compare.getNumExplicitOperands() == 2 &&
2160+
Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
2161+
}
2162+
2163+
unsigned SystemZInstrInfo::
2164+
getCompareSourceReg(const MachineInstr &Compare) const {
2165+
unsigned reg = 0;
2166+
if (Compare.isCompare())
2167+
reg = Compare.getOperand(0).getReg();
2168+
else if (isLoadAndTestAsCmp(Compare))
2169+
reg = Compare.getOperand(1).getReg();
2170+
assert(reg);
2171+
2172+
return reg;
2173+
}
2174+
21472175
bool SystemZInstrInfo::
21482176
prepareCompareSwapOperands(MachineBasicBlock::iterator const MBBI) const {
21492177
assert(MBBI->isCompare() && MBBI->getOperand(0).isReg() &&

llvm/lib/Target/SystemZ/SystemZInstrInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ class SystemZInstrInfo : public SystemZGenInstrInfo {
356356
SystemZII::FusedCompareType Type,
357357
const MachineInstr *MI = nullptr) const;
358358

359+
// Return true if this is a load and test which can be optimized the
360+
// same way as compare instruction.
361+
bool isLoadAndTestAsCmp(const MachineInstr &MI) const;
362+
363+
// Return true if Compare is a comparison against zero.
364+
bool isCompareZero(const MachineInstr &Compare) const;
365+
366+
// Return the source register of Compare, which is the unknown value
367+
// being tested.
368+
unsigned getCompareSourceReg(const MachineInstr &Compare) const;
369+
359370
// Try to find all CC users of the compare instruction (MBBI) and update
360371
// all of them to maintain equivalent behavior after swapping the compare
361372
// operands. Return false if not all users can be conclusively found and

0 commit comments

Comments
 (0)