Lines Matching defs:CmpInstr
1542 /// 1. Convert CmpInstr into an unconditional version.
1543 /// 2. Remove CmpInstr if above there is an instruction producing a needed
1548 MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask,
1550 assert(CmpInstr.getParent());
1555 CmpInstr.findRegisterDefOperandIdx(AArch64::NZCV, /*TRI=*/nullptr, true);
1557 if (CmpInstr.definesRegister(AArch64::WZR, /*TRI=*/nullptr) ||
1558 CmpInstr.definesRegister(AArch64::XZR, /*TRI=*/nullptr)) {
1559 CmpInstr.eraseFromParent();
1562 unsigned Opc = CmpInstr.getOpcode();
1563 unsigned NewOpc = convertToNonFlagSettingOpc(CmpInstr);
1567 CmpInstr.setDesc(MCID);
1568 CmpInstr.removeOperand(DeadNZCVIdx);
1569 bool succeeded = UpdateOperandRegClass(CmpInstr);
1575 if (CmpInstr.getOpcode() == AArch64::PTEST_PP ||
1576 CmpInstr.getOpcode() == AArch64::PTEST_PP_ANY)
1577 return optimizePTestInstr(&CmpInstr, SrcReg, SrcReg2, MRI);
1582 // CmpInstr is a Compare instruction if destination register is not used.
1583 if (!MRI->use_nodbg_empty(CmpInstr.getOperand(0).getReg()))
1586 if (CmpValue == 0 && substituteCmpToZero(CmpInstr, SrcReg, *MRI))
1589 removeCmpToZeroOrOne(CmpInstr, SrcReg, CmpValue, *MRI);
1683 /// codes or we don't optimize CmpInstr in the presence of such instructions.
1735 /// \returns Conditions flags used after \p CmpInstr in its MachineBB if NZCV
1736 /// flags are not alive in successors of the same \p CmpInstr and \p MI parent.
1741 llvm::examineCFlagsUse(MachineInstr &MI, MachineInstr &CmpInstr,
1744 MachineBasicBlock *CmpParent = CmpInstr.getParent();
1753 std::next(CmpInstr.getIterator()), CmpParent->instr_end())) {
1776 /// Check if CmpInstr can be substituted by MI.
1778 /// CmpInstr can be substituted:
1779 /// - CmpInstr is either 'ADDS %vreg, 0' or 'SUBS %vreg, 0'
1780 /// - and, MI and CmpInstr are from the same MachineBB
1781 /// - and, condition flags are not alive in successors of the CmpInstr parent
1783 /// MI and CmpInstr
1785 /// nor uses of flags between MI and CmpInstr.
1786 /// - and, if C/V flags are not used after CmpInstr
1789 static bool canInstrSubstituteCmpInstr(MachineInstr &MI, MachineInstr &CmpInstr,
1795 const unsigned CmpOpcode = CmpInstr.getOpcode();
1799 assert((CmpInstr.getOperand(2).isImm() &&
1800 CmpInstr.getOperand(2).getImm() == 0) &&
1801 "Caller guarantees that CmpInstr compares with constant 0");
1803 std::optional<UsedNZCV> NZVCUsed = examineCFlagsUse(MI, CmpInstr, TRI);
1807 // CmpInstr is either 'ADDS %vreg, 0' or 'SUBS %vreg, 0', and MI is either
1810 // 1) MI and CmpInstr set N and V to the same value.
1812 // signed overflow occurs, so CmpInstr could still be simplified away.
1819 return !areCFlagsAccessedBetweenInstrs(&MI, &CmpInstr, &TRI, AccessToCheck);
1827 MachineInstr &CmpInstr, unsigned SrcReg,
1840 if (!canInstrSubstituteCmpInstr(*MI, CmpInstr, TRI))
1845 CmpInstr.eraseFromParent();
1853 /// \returns True if \p CmpInstr can be removed.
1855 /// \p IsInvertCC is true if, after removing \p CmpInstr, condition
1857 static bool canCmpInstrBeRemoved(MachineInstr &MI, MachineInstr &CmpInstr,
1885 // CmpInstr is 'ADDS %vreg, 0' or 'SUBS %vreg, 0' or 'SUBS %vreg, 1'
1886 const unsigned CmpOpcode = CmpInstr.getOpcode();
1899 examineCFlagsUse(MI, CmpInstr, TRI, &CCUseInstrs);
1900 // Condition flags are not used in CmpInstr basic block successors and only
1901 // Z or N flags allowed to be used after CmpInstr within its basic block
1904 // Z or N flag used after CmpInstr must correspond to the flag used in MI
1908 // If CmpInstr is comparison to zero MI conditions are limited to eq, ne
1912 // There must be no defs of flags between MI and CmpInstr
1913 if (areCFlagsAccessedBetweenInstrs(&MI, &CmpInstr, &TRI, AK_Write))
1917 // 1. MI condition is ne; CmpInstr is 'ADDS %vreg, 0' or 'SUBS %vreg, 0'
1918 // 2. MI condition is eq, pl; CmpInstr is 'SUBS %vreg, 1'
1949 /// \param CmpInstr comparison instruction
1952 MachineInstr &CmpInstr, unsigned SrcReg, int CmpValue,
1960 if (!canCmpInstrBeRemoved(*MI, CmpInstr, CmpValue, TRI, CCUseInstrs,
1964 CmpInstr.eraseFromParent();
1966 // Invert condition codes in CmpInstr CC users