Skip to content

Commit 65246d3

Browse files
committed
Use hasNItemsOrLess() in MRI::hasAtMostUserInstrs().
1 parent 16e0620 commit 65246d3

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

llvm/lib/CodeGen/MachineRegisterInfo.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,8 @@ bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const {
422422

423423
bool MachineRegisterInfo::hasAtMostUserInstrs(Register Reg,
424424
unsigned MaxUsers) const {
425-
unsigned NumUsers = 0;
426-
auto UI = use_instr_nodbg_begin(Reg), UE = use_instr_nodbg_end();
427-
for (; UI != UE && NumUsers < MaxUsers; ++UI)
428-
NumUsers++;
429-
// If we haven't reached the end yet then there are more than MaxUses users.
430-
return UI == UE;
425+
return hasNItemsOrLess(use_instr_nodbg_begin(Reg), use_instr_nodbg_end(),
426+
MaxUsers);
431427
}
432428

433429
/// clearKillFlags - Iterate over all the uses of the given register and

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ bool TargetLoweringBase::shouldLocalize(const MachineInstr &MI,
23252325
auto maxUses = [](unsigned RematCost) {
23262326
// A cost of 1 means remats are basically free.
23272327
if (RematCost == 1)
2328-
return UINT_MAX;
2328+
return std::numeric_limits<unsigned>::max();
23292329
if (RematCost == 2)
23302330
return 2U;
23312331

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20837,7 +20837,7 @@ bool AArch64TargetLowering::shouldLocalize(
2083720837
auto maxUses = [](unsigned RematCost) {
2083820838
// A cost of 1 means remats are basically free.
2083920839
if (RematCost == 1)
20840-
return UINT_MAX;
20840+
return std::numeric_limits<unsigned>::max();
2084120841
if (RematCost == 2)
2084220842
return 2U;
2084320843

@@ -20867,6 +20867,9 @@ bool AArch64TargetLowering::shouldLocalize(
2086720867
unsigned RematCost = *Cost.getValue();
2086820868
Register Reg = MI.getOperand(0).getReg();
2086920869
unsigned MaxUses = maxUses(RematCost);
20870+
// Don't pass UINT_MAX sentinal value to hasAtMostUserInstrs().
20871+
if (MaxUses == std::numeric_limits<unsigned>::max())
20872+
--MaxUses;
2087020873
return MRI.hasAtMostUserInstrs(Reg, MaxUses);
2087120874
}
2087220875
// If we legalized G_GLOBAL_VALUE into ADRP + G_ADD_LOW, mark both as being

0 commit comments

Comments
 (0)