@@ -209,8 +209,8 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
209
209
210
210
// CopyHint is a sortable hint derived from a COPY instruction.
211
211
struct CopyHint {
212
- const Register Reg;
213
- const float Weight;
212
+ Register Reg;
213
+ float Weight;
214
214
CopyHint (Register R, float W) : Reg(R), Weight(W) {}
215
215
bool operator <(const CopyHint &Rhs) const {
216
216
// Always prefer any physreg hint.
@@ -223,8 +223,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
223
223
};
224
224
225
225
bool IsExiting = false ;
226
- std::set<CopyHint> CopyHints;
227
- SmallDenseMap<unsigned , float , 8 > Hint;
226
+ SmallDenseMap<Register, float , 8 > Hint;
228
227
for (MachineRegisterInfo::reg_instr_nodbg_iterator
229
228
I = MRI.reg_instr_nodbg_begin (LI.reg ()),
230
229
E = MRI.reg_instr_nodbg_end ();
@@ -260,8 +259,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
260
259
return -1 .0f ;
261
260
}
262
261
263
- // Force Weight onto the stack so that x86 doesn't add hidden precision,
264
- // similar to HWeight below.
262
+ // Force Weight onto the stack so that x86 doesn't add hidden precision.
265
263
stack_float_t Weight = 1 .0f ;
266
264
if (IsSpillable) {
267
265
// Get loop info for mi.
@@ -287,29 +285,26 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
287
285
if (!TII.isCopyInstr (*MI))
288
286
continue ;
289
287
Register HintReg = copyHint (MI, LI.reg (), TRI, MRI);
290
- if (!HintReg)
291
- continue ;
292
- // Force HWeight onto the stack so that x86 doesn't add hidden precision,
293
- // making the comparison incorrectly pass (i.e., 1 > 1 == true??).
294
- stack_float_t HWeight = Hint[HintReg] += Weight;
295
- if (HintReg.isVirtual () || MRI.isAllocatable (HintReg))
296
- CopyHints.insert (CopyHint (HintReg, HWeight));
288
+ if (HintReg && (HintReg.isVirtual () || MRI.isAllocatable (HintReg)))
289
+ Hint[HintReg] += Weight;
297
290
}
298
291
299
292
// Pass all the sorted copy hints to mri.
300
- if (ShouldUpdateLI && CopyHints .size ()) {
293
+ if (ShouldUpdateLI && Hint .size ()) {
301
294
// Remove a generic hint if previously added by target.
302
295
if (TargetHint.first == 0 && TargetHint.second )
303
296
MRI.clearSimpleHint (LI.reg ());
304
297
305
- SmallSet<Register, 4 > HintedRegs;
306
- for (const auto &Hint : CopyHints) {
307
- if (!HintedRegs.insert (Hint.Reg ).second ||
308
- (TargetHint.first != 0 && Hint.Reg == TargetHint.second ))
309
- // Don't add the same reg twice or the target-type hint again.
310
- continue ;
311
- MRI.addRegAllocationHint (LI.reg (), Hint.Reg );
298
+ // Don't add the target-type hint again.
299
+ Register SkipReg = TargetHint.first != 0 ? TargetHint.second : Register ();
300
+ SmallVector<CopyHint, 8 > RegHints;
301
+ for (const auto &[Reg, Weight] : Hint) {
302
+ if (Reg != SkipReg)
303
+ RegHints.emplace_back (Reg, Weight);
312
304
}
305
+ sort (RegHints);
306
+ for (const auto &[Reg, Weight] : RegHints)
307
+ MRI.addRegAllocationHint (LI.reg (), Reg);
313
308
314
309
// Weakly boost the spill weight of hinted registers.
315
310
TotalWeight *= 1 .01F ;
0 commit comments