Lines Matching defs:CmpInstr

1530 /// 1. Convert CmpInstr into an unconditional version.
1531 /// 2. Remove CmpInstr if above there is an instruction producing a needed
1536 MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask,
1538 assert(CmpInstr.getParent());
1543 CmpInstr.findRegisterDefOperandIdx(AArch64::NZCV, /*TRI=*/nullptr, true);
1545 if (CmpInstr.definesRegister(AArch64::WZR, /*TRI=*/nullptr) ||
1546 CmpInstr.definesRegister(AArch64::XZR, /*TRI=*/nullptr)) {
1547 CmpInstr.eraseFromParent();
1550 unsigned Opc = CmpInstr.getOpcode();
1551 unsigned NewOpc = convertToNonFlagSettingOpc(CmpInstr);
1555 CmpInstr.setDesc(MCID);
1556 CmpInstr.removeOperand(DeadNZCVIdx);
1557 bool succeeded = UpdateOperandRegClass(CmpInstr);
1563 if (CmpInstr.getOpcode() == AArch64::PTEST_PP ||
1564 CmpInstr.getOpcode() == AArch64::PTEST_PP_ANY)
1565 return optimizePTestInstr(&CmpInstr, SrcReg, SrcReg2, MRI);
1570 // CmpInstr is a Compare instruction if destination register is not used.
1571 if (!MRI->use_nodbg_empty(CmpInstr.getOperand(0).getReg()))
1574 if (CmpValue == 0 && substituteCmpToZero(CmpInstr, SrcReg, *MRI))
1577 removeCmpToZeroOrOne(CmpInstr, SrcReg, CmpValue, *MRI);
1671 /// codes or we don't optimize CmpInstr in the presence of such instructions.
1723 /// \returns Conditions flags used after \p CmpInstr in its MachineBB if NZCV
1724 /// flags are not alive in successors of the same \p CmpInstr and \p MI parent.
1729 llvm::examineCFlagsUse(MachineInstr &MI, MachineInstr &CmpInstr,
1732 MachineBasicBlock *CmpParent = CmpInstr.getParent();
1741 std::next(CmpInstr.getIterator()), CmpParent->instr_end())) {
1764 /// Check if CmpInstr can be substituted by MI.
1766 /// CmpInstr can be substituted:
1767 /// - CmpInstr is either 'ADDS %vreg, 0' or 'SUBS %vreg, 0'
1768 /// - and, MI and CmpInstr are from the same MachineBB
1769 /// - and, condition flags are not alive in successors of the CmpInstr parent
1771 /// MI and CmpInstr
1773 /// nor uses of flags between MI and CmpInstr.
1774 /// - and, if C/V flags are not used after CmpInstr
1777 static bool canInstrSubstituteCmpInstr(MachineInstr &MI, MachineInstr &CmpInstr,
1783 const unsigned CmpOpcode = CmpInstr.getOpcode();
1787 assert((CmpInstr.getOperand(2).isImm() &&
1788 CmpInstr.getOperand(2).getImm() == 0) &&
1789 "Caller guarantees that CmpInstr compares with constant 0");
1791 std::optional<UsedNZCV> NZVCUsed = examineCFlagsUse(MI, CmpInstr, TRI);
1795 // CmpInstr is either 'ADDS %vreg, 0' or 'SUBS %vreg, 0', and MI is either
1798 // 1) MI and CmpInstr set N and V to the same value.
1800 // signed overflow occurs, so CmpInstr could still be simplified away.
1807 return !areCFlagsAccessedBetweenInstrs(&MI, &CmpInstr, &TRI, AccessToCheck);
1815 MachineInstr &CmpInstr, unsigned SrcReg,
1828 if (!canInstrSubstituteCmpInstr(*MI, CmpInstr, TRI))
1833 CmpInstr.eraseFromParent();
1841 /// \returns True if \p CmpInstr can be removed.
1843 /// \p IsInvertCC is true if, after removing \p CmpInstr, condition
1845 static bool canCmpInstrBeRemoved(MachineInstr &MI, MachineInstr &CmpInstr,
1873 // CmpInstr is 'ADDS %vreg, 0' or 'SUBS %vreg, 0' or 'SUBS %vreg, 1'
1874 const unsigned CmpOpcode = CmpInstr.getOpcode();
1887 examineCFlagsUse(MI, CmpInstr, TRI, &CCUseInstrs);
1888 // Condition flags are not used in CmpInstr basic block successors and only
1889 // Z or N flags allowed to be used after CmpInstr within its basic block
1892 // Z or N flag used after CmpInstr must correspond to the flag used in MI
1896 // If CmpInstr is comparison to zero MI conditions are limited to eq, ne
1900 // There must be no defs of flags between MI and CmpInstr
1901 if (areCFlagsAccessedBetweenInstrs(&MI, &CmpInstr, &TRI, AK_Write))
1905 // 1. MI condition is ne; CmpInstr is 'ADDS %vreg, 0' or 'SUBS %vreg, 0'
1906 // 2. MI condition is eq, pl; CmpInstr is 'SUBS %vreg, 1'
1937 /// \param CmpInstr comparison instruction
1940 MachineInstr &CmpInstr, unsigned SrcReg, int CmpValue,
1948 if (!canCmpInstrBeRemoved(*MI, CmpInstr, CmpValue, TRI, CCUseInstrs,
1952 CmpInstr.eraseFromParent();
1954 // Invert condition codes in CmpInstr CC users