32 #define DEBUG_TYPE "si-optimize-exec-masking-pre-ra" 48 return "SI optimize exec mask operations pre-RA";
61 "SI optimize exec mask operations pre-RA",
false,
false)
66 char SIOptimizeExecMaskingPreRA::
ID = 0;
71 return new SIOptimizeExecMaskingPreRA();
75 return MI.
getOpcode() == AMDGPU::S_OR_B64 &&
86 if (
Op->isReg() &&
Op->getReg() != AMDGPU::EXEC)
89 if (
Op->isReg() &&
Op->getReg() != AMDGPU::EXEC)
91 return AMDGPU::NoRegister;
98 if (SavedExec == AMDGPU::NoRegister)
106 bool SIOptimizeExecMaskingPreRA::runOnMachineFunction(
MachineFunction &MF) {
116 bool Changed =
false;
121 if (MBB.succ_empty()) {
122 if (MBB.empty() || MBB.back().getOpcode() != AMDGPU::S_ENDPGM)
127 while (!Blocks.empty()) {
129 auto I = CurBB->rbegin(),
E = CurBB->rend();
131 if (
I->isUnconditionalBranch() ||
I->getOpcode() == AMDGPU::S_ENDPGM)
133 else if (
I->isBranch())
138 if (
I->isDebugInstr()) {
143 if (
I->mayStore() ||
I->isBarrier() ||
I->isCall() ||
144 I->hasUnmodeledSideEffects() ||
I->hasOrderedMemoryRef())
148 <<
"Removing no effect instruction: " << *
I <<
'\n');
150 for (
auto &
Op :
I->operands()) {
152 RecalcRegs.insert(
Op.getReg());
155 auto Next = std::next(
I);
157 I->eraseFromParent();
167 for (
auto *Pred : CurBB->predecessors()) {
168 if (Pred->succ_size() == 1)
169 Blocks.push_back(Pred);
176 auto Lead = MBB.begin(),
E = MBB.end();
177 if (MBB.succ_size() != 1 || Lead ==
E || !
isEndCF(*Lead, TRI))
181 if (!MBB.isLayoutSuccessor(Succ))
184 auto I = std::next(Lead);
187 if (!TII->
isSALU(*
I) ||
I->readsRegister(AMDGPU::EXEC, TRI))
193 const auto NextLead = Succ->
begin();
194 if (NextLead == Succ->
end() || !
isEndCF(*NextLead, TRI) ||
198 LLVM_DEBUG(
dbgs() <<
"Redundant EXEC = S_OR_B64 found: " << *Lead <<
'\n');
202 for (
auto &
Op : Lead->operands()) {
204 RecalcRegs.insert(
Op.getReg());
208 Lead->eraseFromParent();
218 if (!SaveExec || !SaveExec->isFullCopy())
221 unsigned SavedExec = SaveExec->getOperand(0).getReg();
222 bool SafeToReplace =
true;
224 if (U.getParent() != SaveExec->getParent()) {
225 SafeToReplace =
false;
229 LLVM_DEBUG(
dbgs() <<
"Redundant EXEC COPY: " << *SaveExec <<
'\n');
234 SaveExec->eraseFromParent();
241 for (
auto Reg : RecalcRegs) {
bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
Compute iterated dominance frontiers using a linear time algorithm.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const SIInstrInfo * getInstrInfo() const override
unsigned const TargetRegisterInfo * TRI
static bool isFullExecCopy(const MachineInstr &MI)
SI optimize exec mask operations pre RA
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
char & SIOptimizeExecMaskingPreRAID
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
INITIALIZE_PASS_BEGIN(SIOptimizeExecMaskingPreRA, DEBUG_TYPE, "SI optimize exec mask operations pre-RA", false, false) INITIALIZE_PASS_END(SIOptimizeExecMaskingPreRA
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
void initializeSIOptimizeExecMaskingPreRAPass(PassRegistry &)
static MachineInstr * getOrExecSource(const MachineInstr &MI, const SIInstrInfo &TII, const MachineRegisterInfo &MRI)
SI optimize exec mask operations
static unsigned getOrNonExecReg(const MachineInstr &MI, const SIInstrInfo &TII)
FunctionPass * createSIOptimizeExecMaskingPreRAPass()
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void removeInterval(unsigned Reg)
Interval removal.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
succ_iterator succ_begin()
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void removeRegUnit(unsigned Unit)
Remove computed live range for register unit Unit.
static bool isSALU(const MachineInstr &MI)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD T pop_back_val()
static bool isEndCF(const MachineInstr &MI, const SIRegisterInfo *TRI)
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
void setPreservesAll()
Set by analyses that do not transform their input at all.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool reg_empty(unsigned RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
LiveInterval & createAndComputeVirtRegInterval(unsigned Reg)
const SIRegisterInfo * getRegisterInfo() const override