@@ -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.
509477bool 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;
0 commit comments