Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/MachineRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ class MachineRegisterInfo {
/// multiple uses.
LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const;

/// If the register has a single non-Debug use, returns it; otherwise returns
/// nullptr.
LLVM_ABI MachineOperand *getOneNonDBGUse(Register RegNo) const;

/// If the register has a single non-Debug instruction using the specified
/// register, returns it; otherwise returns nullptr.
LLVM_ABI MachineInstr *getOneNonDBGUser(Register RegNo) const;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/MachineRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const {
return hasSingleElement(use_nodbg_instructions(RegNo));
}

MachineOperand *MachineRegisterInfo::getOneNonDBGUse(Register RegNo) const {
auto RegNoDbgUses = use_nodbg_operands(RegNo);
return hasSingleElement(RegNoDbgUses) ? &*RegNoDbgUses.begin() : nullptr;
}

MachineInstr *MachineRegisterInfo::getOneNonDBGUser(Register RegNo) const {
auto RegNoDbgUsers = use_nodbg_instructions(RegNo);
return hasSingleElement(RegNoDbgUsers) ? &*RegNoDbgUsers.begin() : nullptr;
Expand Down
28 changes: 2 additions & 26 deletions llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,39 +291,15 @@ static MachineOperand *findSingleRegUse(const MachineOperand *Reg,
if (!Reg->isReg() || !Reg->isDef())
return nullptr;

MachineOperand *ResMO = nullptr;
for (MachineOperand &UseMO : MRI->use_nodbg_operands(Reg->getReg())) {
// If there exist use of subreg of Reg then return nullptr
if (!isSameReg(UseMO, *Reg))
return nullptr;

// Check that there is only one instruction that uses Reg
if (!ResMO) {
ResMO = &UseMO;
} else if (ResMO->getParent() != UseMO.getParent()) {
return nullptr;
}
}

return ResMO;
return MRI->getOneNonDBGUse(Reg->getReg());
}

static MachineOperand *findSingleRegDef(const MachineOperand *Reg,
const MachineRegisterInfo *MRI) {
if (!Reg->isReg())
return nullptr;

MachineInstr *DefInstr = MRI->getUniqueVRegDef(Reg->getReg());
if (!DefInstr)
return nullptr;

for (auto &DefMO : DefInstr->defs()) {
if (DefMO.isReg() && DefMO.getReg() == Reg->getReg())
return &DefMO;
}

// Ignore implicit defs.
return nullptr;
return MRI->getOneDef(Reg->getReg());
}

/// Combine an SDWA instruction's existing SDWA selection \p Sel with
Expand Down
Loading