Skip to content

Commit 5bc72a9

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 45b1a4b commit 5bc72a9

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
-994
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
10951095
NoCand,
10961096
Only1,
10971097
PhysReg,
1098+
LivenessReduce,
10981099
RegExcess,
10991100
RegCritical,
11001101
Stall,
@@ -1229,6 +1230,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
12291230
};
12301231

12311232
// Utility functions used by heuristics in tryCandidate().
1233+
unsigned computeRemLatency(SchedBoundary &CurrZone); // XXX LLVM_ABI?
12321234
LLVM_ABI bool tryLess(int TryVal, int CandVal,
12331235
GenericSchedulerBase::SchedCandidate &TryCand,
12341236
GenericSchedulerBase::SchedCandidate &Cand,

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,31 +3251,6 @@ initResourceDelta(const ScheduleDAGMI *DAG,
32513251
}
32523252
}
32533253

3254-
/// Compute remaining latency. We need this both to determine whether the
3255-
/// overall schedule has become latency-limited and whether the instructions
3256-
/// outside this zone are resource or latency limited.
3257-
///
3258-
/// The "dependent" latency is updated incrementally during scheduling as the
3259-
/// max height/depth of scheduled nodes minus the cycles since it was
3260-
/// scheduled:
3261-
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
3262-
///
3263-
/// The "independent" latency is the max ready queue depth:
3264-
/// ILat = max N.depth for N in Available|Pending
3265-
///
3266-
/// RemainingLatency is the greater of independent and dependent latency.
3267-
///
3268-
/// These computations are expensive, especially in DAGs with many edges, so
3269-
/// only do them if necessary.
3270-
static unsigned computeRemLatency(SchedBoundary &CurrZone) {
3271-
unsigned RemLatency = CurrZone.getDependentLatency();
3272-
RemLatency = std::max(RemLatency,
3273-
CurrZone.findMaxLatency(CurrZone.Available.elements()));
3274-
RemLatency = std::max(RemLatency,
3275-
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
3276-
return RemLatency;
3277-
}
3278-
32793254
/// Returns true if the current cycle plus remaning latency is greater than
32803255
/// the critical path in the scheduling region.
32813256
bool GenericSchedulerBase::shouldReduceLatency(const CandPolicy &Policy,
@@ -3361,6 +3336,7 @@ const char *GenericSchedulerBase::getReasonStr(
33613336
case NoCand: return "NOCAND ";
33623337
case Only1: return "ONLY1 ";
33633338
case PhysReg: return "PHYS-REG ";
3339+
case LivenessReduce: return "LIVE-REDUC";
33643340
case RegExcess: return "REG-EXCESS";
33653341
case RegCritical: return "REG-CRIT ";
33663342
case Stall: return "STALL ";
@@ -3433,6 +3409,31 @@ void GenericSchedulerBase::traceCandidate(const SchedCandidate &Cand) {
34333409
}
34343410
#endif
34353411

3412+
/// Compute remaining latency. We need this both to determine whether the
3413+
/// overall schedule has become latency-limited and whether the instructions
3414+
/// outside this zone are resource or latency limited.
3415+
///
3416+
/// The "dependent" latency is updated incrementally during scheduling as the
3417+
/// max height/depth of scheduled nodes minus the cycles since it was
3418+
/// scheduled:
3419+
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
3420+
///
3421+
/// The "independent" latency is the max ready queue depth:
3422+
/// ILat = max N.depth for N in Available|Pending
3423+
///
3424+
/// RemainingLatency is the greater of independent and dependent latency.
3425+
///
3426+
/// These computations are expensive, especially in DAGs with many edges, so
3427+
/// only do them if necessary.
3428+
unsigned computeRemLatency(SchedBoundary &CurrZone) {
3429+
unsigned RemLatency = CurrZone.getDependentLatency();
3430+
RemLatency = std::max(RemLatency,
3431+
CurrZone.findMaxLatency(CurrZone.Available.elements()));
3432+
RemLatency = std::max(RemLatency,
3433+
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
3434+
return RemLatency;
3435+
}
3436+
34363437
/// Return true if this heuristic determines order.
34373438
/// TODO: Consider refactor return type of these functions as integer or enum,
34383439
/// 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
@@ -150,30 +150,6 @@ Reference SystemZElimCompare::getRegReferences(MachineInstr &MI, unsigned Reg) {
150150
return Ref;
151151
}
152152

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

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

514482
// Search back for CC results that are based on the first operand.
515-
unsigned SrcReg = getCompareSourceReg(Compare);
483+
unsigned SrcReg = TII->getCompareSourceReg(Compare);
516484
MachineBasicBlock &MBB = *Compare.getParent();
517485
Reference CCRefs;
518486
Reference SrcRefs;
@@ -701,7 +669,7 @@ bool SystemZElimCompare::processBlock(MachineBasicBlock &MBB) {
701669
MachineBasicBlock::iterator MBBI = MBB.end();
702670
while (MBBI != MBB.begin()) {
703671
MachineInstr &MI = *--MBBI;
704-
if (CompleteCCUsers && (MI.isCompare() || isLoadAndTestAsCmp(MI)) &&
672+
if (CompleteCCUsers && (MI.isCompare() || TII->isLoadAndTestAsCmp(MI)) &&
705673
(optimizeCompareZero(MI, CCUsers) ||
706674
fuseCompareOperations(MI, CCUsers))) {
707675
++MBBI;

llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,34 @@ unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode,
21562156
return 0;
21572157
}
21582158

2159+
bool SystemZInstrInfo::isLoadAndTestAsCmp(const MachineInstr &MI) const {
2160+
// If we during isel used a load-and-test as a compare with 0, the
2161+
// def operand is dead.
2162+
return (MI.getOpcode() == SystemZ::LTEBR ||
2163+
MI.getOpcode() == SystemZ::LTDBR ||
2164+
MI.getOpcode() == SystemZ::LTXBR) &&
2165+
MI.getOperand(0).isDead();
2166+
}
2167+
2168+
bool SystemZInstrInfo::isCompareZero(const MachineInstr &Compare) const {
2169+
if (isLoadAndTestAsCmp(Compare))
2170+
return true;
2171+
return Compare.isCompare() && Compare.getNumExplicitOperands() == 2 &&
2172+
Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
2173+
}
2174+
2175+
unsigned SystemZInstrInfo::
2176+
getCompareSourceReg(const MachineInstr &Compare) const {
2177+
unsigned reg = 0;
2178+
if (Compare.isCompare())
2179+
reg = Compare.getOperand(0).getReg();
2180+
else if (isLoadAndTestAsCmp(Compare))
2181+
reg = Compare.getOperand(1).getReg();
2182+
assert(reg);
2183+
2184+
return reg;
2185+
}
2186+
21592187
bool SystemZInstrInfo::
21602188
prepareCompareSwapOperands(MachineBasicBlock::iterator const MBBI) const {
21612189
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)