@@ -209,8 +209,8 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
209209
210210 // CopyHint is a sortable hint derived from a COPY instruction.
211211 struct CopyHint {
212- const Register Reg;
213- const float Weight;
212+ Register Reg;
213+ float Weight;
214214 CopyHint (Register R, float W) : Reg(R), Weight(W) {}
215215 bool operator <(const CopyHint &Rhs) const {
216216 // Always prefer any physreg hint.
@@ -223,8 +223,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
223223 };
224224
225225 bool IsExiting = false ;
226- std::set<CopyHint> CopyHints;
227- SmallDenseMap<unsigned , float , 8 > Hint;
226+ SmallDenseMap<Register, float , 8 > Hint;
228227 for (MachineRegisterInfo::reg_instr_nodbg_iterator
229228 I = MRI.reg_instr_nodbg_begin (LI.reg ()),
230229 E = MRI.reg_instr_nodbg_end ();
@@ -260,8 +259,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
260259 return -1 .0f ;
261260 }
262261
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.
265263 stack_float_t Weight = 1 .0f ;
266264 if (IsSpillable) {
267265 // Get loop info for mi.
@@ -287,29 +285,26 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
287285 if (!TII.isCopyInstr (*MI))
288286 continue ;
289287 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;
297290 }
298291
299292 // Pass all the sorted copy hints to mri.
300- if (ShouldUpdateLI && CopyHints .size ()) {
293+ if (ShouldUpdateLI && Hint .size ()) {
301294 // Remove a generic hint if previously added by target.
302295 if (TargetHint.first == 0 && TargetHint.second )
303296 MRI.clearSimpleHint (LI.reg ());
304297
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);
312304 }
305+ sort (RegHints);
306+ for (const auto &[Reg, Weight] : RegHints)
307+ MRI.addRegAllocationHint (LI.reg (), Reg);
313308
314309 // Weakly boost the spill weight of hinted registers.
315310 TotalWeight *= 1 .01F ;
0 commit comments