@@ -207,24 +207,8 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
207
207
NumInstr += 2 ;
208
208
}
209
209
210
- // CopyHint is a sortable hint derived from a COPY instruction.
211
- struct CopyHint {
212
- const Register Reg;
213
- const float Weight;
214
- CopyHint (Register R, float W) : Reg(R), Weight(W) {}
215
- bool operator <(const CopyHint &Rhs) const {
216
- // Always prefer any physreg hint.
217
- if (Reg.isPhysical () != Rhs.Reg .isPhysical ())
218
- return Reg.isPhysical ();
219
- if (Weight != Rhs.Weight )
220
- return (Weight > Rhs.Weight );
221
- return Reg.id () < Rhs.Reg .id (); // Tie-breaker.
222
- }
223
- };
224
-
225
210
bool IsExiting = false ;
226
- std::set<CopyHint> CopyHints;
227
- SmallDenseMap<unsigned , float , 8 > Hint;
211
+ SmallDenseMap<Register, float , 8 > Hint;
228
212
for (MachineRegisterInfo::reg_instr_nodbg_iterator
229
213
I = MRI.reg_instr_nodbg_begin (LI.reg ()),
230
214
E = MRI.reg_instr_nodbg_end ();
@@ -260,8 +244,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
260
244
return -1 .0f ;
261
245
}
262
246
263
- // Force Weight onto the stack so that x86 doesn't add hidden precision,
264
- // similar to HWeight below.
247
+ // Force Weight onto the stack so that x86 doesn't add hidden precision.
265
248
stack_float_t Weight = 1 .0f ;
266
249
if (IsSpillable) {
267
250
// Get loop info for mi.
@@ -287,29 +270,34 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
287
270
if (!TII.isCopyInstr (*MI))
288
271
continue ;
289
272
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));
273
+ if (HintReg && (HintReg.isVirtual () || MRI.isAllocatable (HintReg)))
274
+ Hint[HintReg] += Weight;
297
275
}
298
276
299
277
// Pass all the sorted copy hints to mri.
300
- if (ShouldUpdateLI && CopyHints .size ()) {
278
+ if (ShouldUpdateLI && Hint .size ()) {
301
279
// Remove a generic hint if previously added by target.
302
280
if (TargetHint.first == 0 && TargetHint.second )
303
281
MRI.clearSimpleHint (LI.reg ());
304
282
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 );
283
+ // Don't add the target-type hint again.
284
+ Register SkipReg = TargetHint.first != 0 ? TargetHint.second : Register ();
285
+ SmallVector<std::pair<float , Register>, 4 > FRegHints, VRegHints;
286
+ for (const auto &[Reg, Weight] : Hint) {
287
+ if (Reg != SkipReg)
288
+ (Reg.isPhysical () ? &FRegHints : &VRegHints)->emplace_back (Weight, Reg);
312
289
}
290
+ auto HeavyFirst = [](const auto &LHS, const auto &RHS) {
291
+ if (LHS.first != RHS.first )
292
+ return LHS.first > RHS.first ;
293
+ return LHS.second .id () < RHS.second .id ();
294
+ };
295
+ sort (FRegHints, HeavyFirst);
296
+ sort (VRegHints, HeavyFirst);
297
+ for (const auto &[Weight, Reg] : FRegHints) // Prefer physregs hints first.
298
+ MRI.addRegAllocationHint (LI.reg (), Reg);
299
+ for (const auto &[Weight, Reg] : VRegHints)
300
+ MRI.addRegAllocationHint (LI.reg (), Reg);
313
301
314
302
// Weakly boost the spill weight of hinted registers.
315
303
TotalWeight *= 1 .01F ;
0 commit comments