Use hasNItemsOrLess() in MRI::hasAtMostUserInstrs().

This commit is contained in:
Amara Emerson 2022-07-27 11:11:46 -07:00
parent 16e0620d6d
commit 65246d3eb4
3 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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;

View File

@ -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