[llvm] 65246d3 - Use hasNItemsOrLess() in MRI::hasAtMostUserInstrs().
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 27 11:42:20 PDT 2022
Author: Amara Emerson
Date: 2022-07-27T11:42:14-07:00
New Revision: 65246d3eb4c64b338f8011dab5ee9ee2cc62c5c3
URL: https://github.com/llvm/llvm-project/commit/65246d3eb4c64b338f8011dab5ee9ee2cc62c5c3
DIFF: https://github.com/llvm/llvm-project/commit/65246d3eb4c64b338f8011dab5ee9ee2cc62c5c3.diff
LOG: Use hasNItemsOrLess() in MRI::hasAtMostUserInstrs().
Added:
Modified:
llvm/lib/CodeGen/MachineRegisterInfo.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
index dc109cd3aeca..c96de7ab5c59 100644
--- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -422,12 +422,8 @@ bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const {
bool MachineRegisterInfo::hasAtMostUserInstrs(Register Reg,
unsigned MaxUsers) const {
- unsigned NumUsers = 0;
- auto UI = use_instr_nodbg_begin(Reg), UE = use_instr_nodbg_end();
- for (; UI != UE && NumUsers < MaxUsers; ++UI)
- NumUsers++;
- // If we haven't reached the end yet then there are more than MaxUses users.
- return UI == UE;
+ return hasNItemsOrLess(use_instr_nodbg_begin(Reg), use_instr_nodbg_end(),
+ MaxUsers);
}
/// clearKillFlags - Iterate over all the uses of the given register and
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 517e835c385e..f7c10008bf11 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2325,7 +2325,7 @@ bool TargetLoweringBase::shouldLocalize(const MachineInstr &MI,
auto maxUses = [](unsigned RematCost) {
// A cost of 1 means remats are basically free.
if (RematCost == 1)
- return UINT_MAX;
+ return std::numeric_limits<unsigned>::max();
if (RematCost == 2)
return 2U;
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 08ddab4d2fc1..c21470def5e7 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -20837,7 +20837,7 @@ bool AArch64TargetLowering::shouldLocalize(
auto maxUses = [](unsigned RematCost) {
// A cost of 1 means remats are basically free.
if (RematCost == 1)
- return UINT_MAX;
+ return std::numeric_limits<unsigned>::max();
if (RematCost == 2)
return 2U;
@@ -20867,6 +20867,9 @@ bool AArch64TargetLowering::shouldLocalize(
unsigned RematCost = *Cost.getValue();
Register Reg = MI.getOperand(0).getReg();
unsigned MaxUses = maxUses(RematCost);
+ // Don't pass UINT_MAX sentinal value to hasAtMostUserInstrs().
+ if (MaxUses == std::numeric_limits<unsigned>::max())
+ --MaxUses;
return MRI.hasAtMostUserInstrs(Reg, MaxUses);
}
// If we legalized G_GLOBAL_VALUE into ADRP + G_ADD_LOW, mark both as being
More information about the llvm-commits
mailing list