[llvm] 9b4b9de - [MRI] Avoid walking past all defs in hasOneUse() (#201249)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 7 18:08:11 PDT 2026
Author: Mingjie Xu
Date: 2026-06-08T09:08:07+08:00
New Revision: 9b4b9de0319b63ff56dd157b1d12465f206681f6
URL: https://github.com/llvm/llvm-project/commit/9b4b9de0319b63ff56dd157b1d12465f206681f6
DIFF: https://github.com/llvm/llvm-project/commit/9b4b9de0319b63ff56dd157b1d12465f206681f6.diff
LOG: [MRI] Avoid walking past all defs in hasOneUse() (#201249)
The use-def list is circular in the Prev direction (Head->Prev == Tail)
and defs always precede uses, see
MachineRegisterInfo::addRegOperandToUseList().
We can implement hasOneUse() by checking only the Tail and its Prev,
instead of
walking past all defs from the head via use_iterator.
Added:
Modified:
llvm/include/llvm/CodeGen/MachineRegisterInfo.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
index 737b74ef3f761..2c29c8bbd0b31 100644
--- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -511,7 +511,16 @@ class MachineRegisterInfo {
/// hasOneUse - Return true if there is exactly one instruction using the
/// specified register.
bool hasOneUse(Register RegNo) const {
- return hasSingleElement(use_operands(RegNo));
+ MachineOperand *Head = getRegUseDefListHead(RegNo);
+ if (!Head)
+ return false;
+ // Prev links are circular, and defs always precede uses.
+ MachineOperand *Tail = Head->Contents.Reg.Prev;
+ if (!Tail->isUse())
+ return false;
+ if (Tail == Head)
+ return true;
+ return Tail->Contents.Reg.Prev->isDef();
}
/// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the
More information about the llvm-commits
mailing list