Combine sort keys into u64/u128

This allows the compiler to perform branch-less comparisons, which are
more efficient.

This results in ~5% fewer instructions executed.
This commit is contained in:
Amanieu d'Antras
2022-01-11 10:38:50 +00:00
parent 053375f049
commit d95a9d9399
5 changed files with 44 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ use super::{
SpillSetIndex, Use, VRegData, VRegIndex, SLOT_NONE,
};
use crate::indexset::IndexSet;
use crate::ion::data_structures::MultiFixedRegFixup;
use crate::ion::data_structures::{u128_key, MultiFixedRegFixup};
use crate::{
Allocation, Block, Function, Inst, InstPosition, Operand, OperandConstraint, OperandKind,
OperandPos, PReg, ProgPoint, RegAllocError, VReg,
@@ -1141,8 +1141,24 @@ impl<'a, F: Function> Env<'a, F> {
}
}
self.blockparam_ins.sort_unstable();
self.blockparam_outs.sort_unstable();
self.blockparam_ins
.sort_unstable_by_key(|(to_vreg, to_block, from_block)| {
u128_key(
to_vreg.raw_u32(),
to_block.raw_u32(),
from_block.raw_u32(),
0,
)
});
self.blockparam_outs
.sort_unstable_by_key(|(from_vreg, from_block, to_block, to_vreg)| {
u128_key(
from_vreg.raw_u32(),
from_block.raw_u32(),
to_block.raw_u32(),
to_vreg.raw_u32(),
)
});
self.prog_move_srcs.sort_unstable_by_key(|(pos, _)| *pos);
self.prog_move_dsts.sort_unstable_by_key(|(pos, _)| *pos);