27#define DEBUG_TYPE "aarch64-post-select-optimize"
39 return "AArch64 Post Select Optimizer";
55void AArch64PostSelectOptimize::getAnalysisUsage(
AnalysisUsage &AU)
const {
66 case AArch64::SUBSXrr:
67 return AArch64::SUBXrr;
68 case AArch64::SUBSWrr:
69 return AArch64::SUBWrr;
70 case AArch64::SUBSXrs:
71 return AArch64::SUBXrs;
72 case AArch64::SUBSWrs:
73 return AArch64::SUBWrs;
74 case AArch64::SUBSXri:
75 return AArch64::SUBXri;
76 case AArch64::SUBSWri:
77 return AArch64::SUBWri;
78 case AArch64::ADDSXrr:
79 return AArch64::ADDXrr;
80 case AArch64::ADDSWrr:
81 return AArch64::ADDWrr;
82 case AArch64::ADDSXrs:
83 return AArch64::ADDXrs;
84 case AArch64::ADDSWrs:
85 return AArch64::ADDWrs;
86 case AArch64::ADDSXri:
87 return AArch64::ADDXri;
88 case AArch64::ADDSWri:
89 return AArch64::ADDWri;
91 return AArch64::SBCXr;
93 return AArch64::SBCWr;
95 return AArch64::ADCXr;
97 return AArch64::ADCWr;
102 bool Changed =
false;
104 bool CurrentIterChanged = foldSimpleCrossClassCopies(
MI);
105 if (!CurrentIterChanged)
106 CurrentIterChanged |= foldCopyDup(
MI);
107 Changed |= CurrentIterChanged;
112bool AArch64PostSelectOptimize::foldSimpleCrossClassCopies(
MachineInstr &
MI) {
113 auto *MF =
MI.getMF();
114 auto &
MRI = MF->getRegInfo();
119 if (
MI.getOperand(1).getSubReg())
125 if (Src.isPhysical() || Dst.isPhysical())
140 if (!
MRI.hasOneNonDBGUse(Src))
145 if (!
MRI.constrainRegClass(Src, DstRC, 25))
155 MRI.replaceRegWith(Dst, Src);
156 MI.eraseFromParent();
164 auto *MF =
MI.getMF();
165 auto &
MRI = MF->getRegInfo();
166 auto *
TII = MF->getSubtarget().getInstrInfo();
173 if (!Dst.isVirtual() || !Src.isVirtual())
179 if (
MRI.getRegClassOrNull(Dst) != GPRRegClass ||
180 MRI.getRegClassOrNull(Src) != FPRRegClass)
187 for (
auto &
Use :
MRI.use_nodbg_instructions(Dst)) {
196 if (
MRI.getRegClassOrNull(UseOp0) == FPRRegClass &&
197 MRI.getRegClassOrNull(UseOp1) == GPRRegClass)
202 if (!SrcMI || SrcMI->
getOpcode() != DUP || !
MRI.hasOneNonDBGUse(Src))
212 MI.eraseFromParent();
216 return TryMatchDUP(&AArch64::GPR32RegClass, &AArch64::FPR32RegClass,
217 AArch64::DUPi32, AArch64::UMOVvi32) ||
218 TryMatchDUP(&AArch64::GPR64RegClass, &AArch64::FPR64RegClass,
219 AArch64::DUPi64, AArch64::UMOVvi64);
250 bool Changed =
false;
253 const auto &
TII = Subtarget.getInstrInfo();
254 auto TRI = Subtarget.getRegisterInfo();
255 auto RBI = Subtarget.getRegBankInfo();
256 auto &
MRI = MF.getRegInfo();
259 LRU.addLiveOuts(
MBB);
262 bool NZCVDead = LRU.available(AArch64::NZCV);
263 if (NZCVDead &&
II.definesRegister(AArch64::NZCV,
nullptr)) {
267 II.findRegisterDefOperandIdx(AArch64::NZCV,
nullptr);
268 if (DeadNZCVIdx != -1) {
271 LLVM_DEBUG(
dbgs() <<
"Post-select optimizer: converting flag-setting "
274 II.setDesc(
TII->get(NewOpc));
275 II.removeOperand(DeadNZCVIdx);
280 II.getOperand(0), 0);
285 II.getOperand(DeadNZCVIdx).setIsDead();
289 LRU.stepBackward(
II);
294bool AArch64PostSelectOptimize::runOnMachineFunction(
MachineFunction &MF) {
299 bool Changed =
false;
300 for (
auto &BB : MF) {
301 Changed |= optimizeNZCVDefs(BB);
302 Changed |= doPeepholeOpts(BB);
307char AArch64PostSelectOptimize::ID = 0;
309 "Optimize AArch64 selected instructions",
317 return new AArch64PostSelectOptimize();
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned getNonFlagSettingVariant(unsigned Opc)
Optimize AArch64 selected instructions
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
A set of register units used to track register liveness.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
reverse_iterator rbegin()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
StringRef - Represent a constant reference to a string, i.e.
Target-Independent Code Generator Pass Configuration Options.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
A Use represents the edge between a Value definition and its users.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createAArch64PostSelectOptimize()
LLVM_ABI Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.