Lines Matching full:compare
11 // (2) fuses compares and branches into COMPARE AND BRANCH instructions
36 #define DEBUG_TYPE "systemz-elim-compare"
41 STATISTIC(FusedComparisons, "Number of fused compare-and-branch instructions");
82 bool convertToBRCT(MachineInstr &MI, MachineInstr &Compare,
84 bool convertToLoadAndTrap(MachineInstr &MI, MachineInstr &Compare,
86 bool convertToLoadAndTest(MachineInstr &MI, MachineInstr &Compare,
88 bool convertToLogical(MachineInstr &MI, MachineInstr &Compare,
90 bool adjustCCMasksForInstr(MachineInstr &MI, MachineInstr &Compare,
93 bool optimizeCompareZero(MachineInstr &Compare,
95 bool fuseCompareOperations(MachineInstr &Compare,
157 // same way as compare instruction.
159 // If we during isel used a load-and-test as a compare with 0, the in isLoadAndTestAsCmp()
167 // Return the source register of Compare, which is the unknown value
169 static unsigned getCompareSourceReg(MachineInstr &Compare) { in getCompareSourceReg() argument
171 if (Compare.isCompare()) in getCompareSourceReg()
172 reg = Compare.getOperand(0).getReg(); in getCompareSourceReg()
173 else if (isLoadAndTestAsCmp(Compare)) in getCompareSourceReg()
174 reg = Compare.getOperand(1).getReg(); in getCompareSourceReg()
180 // Compare compares the result of MI against zero. If MI is an addition
184 MachineInstr &MI, MachineInstr &Compare, in convertToBRCT() argument
210 // MI and Compare. Make sure that there are also no references between in convertToBRCT()
211 // Compare and Branch. in convertToBRCT()
212 unsigned SrcReg = getCompareSourceReg(Compare); in convertToBRCT()
213 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch; in convertToBRCT()
234 // Compare compares the result of MI against zero. If MI is a suitable load
238 MachineInstr &MI, MachineInstr &Compare, in convertToLoadAndTrap() argument
254 // MI and Compare. Make sure that there are also no references between in convertToLoadAndTrap()
255 // Compare and Branch. in convertToLoadAndTrap()
256 unsigned SrcReg = getCompareSourceReg(Compare); in convertToLoadAndTrap()
257 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch; in convertToLoadAndTrap()
278 MachineInstr &MI, MachineInstr &Compare, in convertToLoadAndTest() argument
283 if (!Opcode || !adjustCCMasksForInstr(MI, Compare, CCUsers, Opcode)) in convertToLoadAndTest()
295 if (!Compare.mayRaiseFPException()) in convertToLoadAndTest()
306 MachineInstr &MI, MachineInstr &Compare, in convertToLogical() argument
320 if (!ConvOpc || !adjustCCMasksForInstr(MI, Compare, CCUsers, ConvOpc)) in convertToLogical()
354 MachineInstr &MI, MachineInstr &Compare, in adjustCCMasksForInstr() argument
357 unsigned CompareFlags = Compare.getDesc().TSFlags; in adjustCCMasksForInstr()
363 // If Compare may raise an FP exception, we can only eliminate it in adjustCCMasksForInstr()
365 if (Compare.mayRaiseFPException()) { in adjustCCMasksForInstr()
375 // See which compare-style condition codes are available. in adjustCCMasksForInstr()
472 // Check if MI lies before Compare. in adjustCCMasksForInstr()
476 if (MBBI == Compare) { in adjustCCMasksForInstr()
483 MachineBasicBlock::iterator MBBI = MI, MBBE = Compare; in adjustCCMasksForInstr()
491 // Return true if Compare is a comparison against zero.
492 static bool isCompareZero(MachineInstr &Compare) { in isCompareZero() argument
493 if (isLoadAndTestAsCmp(Compare)) in isCompareZero()
495 return Compare.getNumExplicitOperands() == 2 && in isCompareZero()
496 Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0; in isCompareZero()
499 // Try to optimize cases where comparison instruction Compare is testing
500 // a value against zero. Return true on success and if Compare should be
502 // value produced by Compare.
504 MachineInstr &Compare, SmallVectorImpl<MachineInstr *> &CCUsers) { in optimizeCompareZero() argument
505 if (!isCompareZero(Compare)) in optimizeCompareZero()
509 unsigned SrcReg = getCompareSourceReg(Compare); in optimizeCompareZero()
510 MachineBasicBlock &MBB = *Compare.getParent(); in optimizeCompareZero()
514 std::next(MachineBasicBlock::reverse_iterator(&Compare)), in optimizeCompareZero()
518 // Try to remove both MI and Compare by converting a branch to BRCT(G). in optimizeCompareZero()
520 // CC is modified between MI and Compare. in optimizeCompareZero()
522 if (convertToBRCT(MI, Compare, CCUsers)) { in optimizeCompareZero()
526 if (convertToLoadAndTrap(MI, Compare, CCUsers)) { in optimizeCompareZero()
531 // Try to eliminate Compare by reusing a CC result from MI. in optimizeCompareZero()
532 if ((!CCRefs && convertToLoadAndTest(MI, Compare, CCUsers)) || in optimizeCompareZero()
534 (adjustCCMasksForInstr(MI, Compare, CCUsers) || in optimizeCompareZero()
535 convertToLogical(MI, Compare, CCUsers)))) { in optimizeCompareZero()
546 // Eliminating a Compare that may raise an FP exception will move in optimizeCompareZero()
549 if (Compare.mayRaiseFPException() && in optimizeCompareZero()
555 // compare can be converted, like in optimizeCompareZero()
558 std::next(MachineBasicBlock::iterator(&Compare)), MBB.end()); in optimizeCompareZero()
561 // Try to eliminate Compare by reusing a CC result from MI. in optimizeCompareZero()
562 if (convertToLoadAndTest(MI, Compare, CCUsers)) { in optimizeCompareZero()
576 // Try to fuse comparison instruction Compare into a later branch.
577 // Return true on success and if Compare is therefore redundant.
579 MachineInstr &Compare, SmallVectorImpl<MachineInstr *> &CCUsers) { in fuseCompareOperations() argument
604 TII->getFusedCompare(Compare.getOpcode(), Type, &Compare); in fuseCompareOperations()
612 Register SrcReg = Compare.getOperand(0).getReg(); in fuseCompareOperations()
614 Compare.getOperand(1).isReg() ? Compare.getOperand(1).getReg() : Register(); in fuseCompareOperations()
615 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch; in fuseCompareOperations()
647 // Rebuild Branch as a fused compare and branch. in fuseCompareOperations()
648 // SrcNOps is the number of MI operands of the compare instruction in fuseCompareOperations()
656 MIB.add(Compare.getOperand(I)); in fuseCompareOperations()
673 MBBI = Compare; in fuseCompareOperations()
689 // all CC users as we go. The subroutines can delete Compare and in processBlock()