Skip to content

Commit 42fd586

Browse files
committed
HighSUs, 4 SeqNodes instead of TinyRegion.
Help Cmp0 elim. Fixes after rebase. Refactoring. Tests updated. Try without TinyRegion (Cmp-0, PReg COPYs) IsSchedLowCand() Experiments with ShouldReduceLiveness. Was c13f7bc (e2dbbe7)
1 parent 686683c commit 42fd586

30 files changed

+1011
-1055
lines changed

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3429,7 +3429,7 @@ void GenericSchedulerBase::traceCandidate(const SchedCandidate &Cand) {
34293429
///
34303430
/// These computations are expensive, especially in DAGs with many edges, so
34313431
/// only do them if necessary.
3432-
unsigned computeRemLatency(SchedBoundary &CurrZone) {
3432+
unsigned llvm::computeRemLatency(SchedBoundary &CurrZone) {
34333433
unsigned RemLatency = CurrZone.getDependentLatency();
34343434
RemLatency = std::max(RemLatency,
34353435
CurrZone.findMaxLatency(CurrZone.Available.elements()));

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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,28 @@ 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+
Register
2176+
SystemZInstrInfo::getCompareSourceReg(const MachineInstr &Compare) const {
2177+
assert(isCompareZero(Compare) && "Expected a compare with 0.");
2178+
return Compare.getOperand(isLoadAndTestAsCmp(Compare) ? 1 : 0).getReg();
2179+
}
2180+
21592181
bool SystemZInstrInfo::
21602182
prepareCompareSwapOperands(MachineBasicBlock::iterator const MBBI) const {
21612183
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+
Register 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)