Skip to content

Commit d0d79fd

Browse files
authored
[AMDGPU] si-peephole-sdwa: reuse getOne{NonDBGUse,Def} (NFC) (llvm#156455)
This patch changes the findSingleRegDef function from si-peephole-sdwa to reuse MachineRegisterInfo::getOneDef and findSingleRefUse to use a new MachineRegisterInfo::getOneNonDBGUse function.
1 parent 653c403 commit d0d79fd

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

llvm/include/llvm/CodeGen/MachineRegisterInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ class MachineRegisterInfo {
579579
/// multiple uses.
580580
LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const;
581581

582+
/// If the register has a single non-Debug use, returns it; otherwise returns
583+
/// nullptr.
584+
LLVM_ABI MachineOperand *getOneNonDBGUse(Register RegNo) const;
585+
582586
/// If the register has a single non-Debug instruction using the specified
583587
/// register, returns it; otherwise returns nullptr.
584588
LLVM_ABI MachineInstr *getOneNonDBGUser(Register RegNo) const;

llvm/lib/CodeGen/MachineRegisterInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const {
432432
return hasSingleElement(use_nodbg_instructions(RegNo));
433433
}
434434

435+
MachineOperand *MachineRegisterInfo::getOneNonDBGUse(Register RegNo) const {
436+
auto RegNoDbgUses = use_nodbg_operands(RegNo);
437+
return hasSingleElement(RegNoDbgUses) ? &*RegNoDbgUses.begin() : nullptr;
438+
}
439+
435440
MachineInstr *MachineRegisterInfo::getOneNonDBGUser(Register RegNo) const {
436441
auto RegNoDbgUsers = use_nodbg_instructions(RegNo);
437442
return hasSingleElement(RegNoDbgUsers) ? &*RegNoDbgUsers.begin() : nullptr;

llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -291,39 +291,15 @@ static MachineOperand *findSingleRegUse(const MachineOperand *Reg,
291291
if (!Reg->isReg() || !Reg->isDef())
292292
return nullptr;
293293

294-
MachineOperand *ResMO = nullptr;
295-
for (MachineOperand &UseMO : MRI->use_nodbg_operands(Reg->getReg())) {
296-
// If there exist use of subreg of Reg then return nullptr
297-
if (!isSameReg(UseMO, *Reg))
298-
return nullptr;
299-
300-
// Check that there is only one instruction that uses Reg
301-
if (!ResMO) {
302-
ResMO = &UseMO;
303-
} else if (ResMO->getParent() != UseMO.getParent()) {
304-
return nullptr;
305-
}
306-
}
307-
308-
return ResMO;
294+
return MRI->getOneNonDBGUse(Reg->getReg());
309295
}
310296

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

316-
MachineInstr *DefInstr = MRI->getUniqueVRegDef(Reg->getReg());
317-
if (!DefInstr)
318-
return nullptr;
319-
320-
for (auto &DefMO : DefInstr->defs()) {
321-
if (DefMO.isReg() && DefMO.getReg() == Reg->getReg())
322-
return &DefMO;
323-
}
324-
325-
// Ignore implicit defs.
326-
return nullptr;
302+
return MRI->getOneDef(Reg->getReg());
327303
}
328304

329305
/// Combine an SDWA instruction's existing SDWA selection \p Sel with

0 commit comments

Comments
 (0)