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
167 // Return the source register of Compare, which is the unknown value
169 static unsigned getCompareSourceReg(MachineInstr &Compare) {
171 if (Compare.isCompare())
172 reg = Compare.getOperand(0).getReg();
173 else if (isLoadAndTestAsCmp(Compare))
174 reg = Compare.getOperand(1).getReg();
180 // Compare compares the result of MI against zero. If MI is an addition
184 MachineInstr &MI, MachineInstr &Compare,
210 // MI and Compare. Make sure that there are also no references between
211 // Compare and Branch.
212 unsigned SrcReg = getCompareSourceReg(Compare);
213 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch;
234 // Compare compares the result of MI against zero. If MI is a suitable load
238 MachineInstr &MI, MachineInstr &Compare,
254 // MI and Compare. Make sure that there are also no references between
255 // Compare and Branch.
256 unsigned SrcReg = getCompareSourceReg(Compare);
257 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch;
278 MachineInstr &MI, MachineInstr &Compare,
283 if (!Opcode || !adjustCCMasksForInstr(MI, Compare, CCUsers, Opcode))
295 if (!Compare.mayRaiseFPException())
306 MachineInstr &MI, MachineInstr &Compare,
320 if (!ConvOpc || !adjustCCMasksForInstr(MI, Compare, CCUsers, ConvOpc))
354 MachineInstr &MI, MachineInstr &Compare,
357 unsigned CompareFlags = Compare.getDesc().TSFlags;
363 // If Compare may raise an FP exception, we can only eliminate it
365 if (Compare.mayRaiseFPException()) {
375 // See which compare-style condition codes are available.
472 // Check if MI lies before Compare.
476 if (MBBI == Compare) {
483 MachineBasicBlock::iterator MBBI = MI, MBBE = Compare;
491 // Return true if Compare is a comparison against zero.
492 static bool isCompareZero(MachineInstr &Compare) {
493 if (isLoadAndTestAsCmp(Compare))
495 return Compare.getNumExplicitOperands() == 2 &&
496 Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
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) {
505 if (!isCompareZero(Compare))
509 unsigned SrcReg = getCompareSourceReg(Compare);
510 MachineBasicBlock &MBB = *Compare.getParent();
514 std::next(MachineBasicBlock::reverse_iterator(&Compare)),
518 // Try to remove both MI and Compare by converting a branch to BRCT(G).
520 // CC is modified between MI and Compare.
522 if (convertToBRCT(MI, Compare, CCUsers)) {
526 if (convertToLoadAndTrap(MI, Compare, CCUsers)) {
531 // Try to eliminate Compare by reusing a CC result from MI.
532 if ((!CCRefs && convertToLoadAndTest(MI, Compare, CCUsers)) ||
534 (adjustCCMasksForInstr(MI, Compare, CCUsers) ||
535 convertToLogical(MI, Compare, CCUsers)))) {
546 // Eliminating a Compare that may raise an FP exception will move
549 if (Compare.mayRaiseFPException() &&
555 // compare can be converted, like
558 std::next(MachineBasicBlock::iterator(&Compare)), MBB.end());
561 // Try to eliminate Compare by reusing a CC result from MI.
562 if (convertToLoadAndTest(MI, Compare, CCUsers)) {
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) {
604 TII->getFusedCompare(Compare.getOpcode(), Type, &Compare);
612 Register SrcReg = Compare.getOperand(0).getReg();
614 Compare.getOperand(1).isReg() ? Compare.getOperand(1).getReg() : Register();
615 MachineBasicBlock::iterator MBBI = Compare, MBBE = Branch;
647 // Rebuild Branch as a fused compare and branch.
648 // SrcNOps is the number of MI operands of the compare instruction
656 MIB.add(Compare.getOperand(I));
673 MBBI = Compare;
689 // all CC users as we go. The subroutines can delete Compare and