Skip to content

Commit 60b4cb3

Browse files
committed
Ensure all fixed registers fit within their Limit
Operands can be constrained to fixed registers, potentially multiple _different_ fixed registers; `Env::fixup_multi_fixed_vregs` fixes this. Here we also check that, for all the uses of a fixed register, the fixed register chosen does not fall outside of any limit constraints. To do this, we find the _lowest_ (minimum) limit in all uses of the operand and ensure the fixed register is below that.
1 parent 54d1926 commit 60b4cb3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/ion/liveranges.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{
2525
OperandPos, PReg, ProgPoint, RegAllocError, VReg, VecExt,
2626
};
2727
use core::convert::TryFrom;
28+
use core::usize;
2829
use smallvec::{smallvec, SmallVec};
2930

3031
/// A spill weight computed for a certain Use.
@@ -804,6 +805,8 @@ impl<'a, F: Function> Env<'a, F> {
804805
let mut num_fixed_stack = 0;
805806
let mut first_reg_slot = None;
806807
let mut first_stack_slot = None;
808+
let mut min_limit = usize::MAX;
809+
let mut max_fixed_reg = usize::MIN;
807810
for u in uses.iter() {
808811
match u.operand.constraint() {
809812
OperandConstraint::Any => {
@@ -814,7 +817,13 @@ impl<'a, F: Function> Env<'a, F> {
814817
first_reg_slot.get_or_insert(u.slot);
815818
requires_reg = true;
816819
}
820+
OperandConstraint::Limit(max) => {
821+
first_reg_slot.get_or_insert(u.slot);
822+
min_limit = min_limit.min(max);
823+
requires_reg = true;
824+
}
817825
OperandConstraint::FixedReg(preg) => {
826+
max_fixed_reg = max_fixed_reg.max(preg.hw_enc());
818827
if self.ctx.pregs[preg.index()].is_stack {
819828
num_fixed_stack += 1;
820829
first_stack_slot.get_or_insert(u.slot);
@@ -834,6 +843,7 @@ impl<'a, F: Function> Env<'a, F> {
834843
// Fast path if there are no conflicts.
835844
if num_fixed_reg + num_fixed_stack <= 1
836845
&& !(requires_reg && num_fixed_stack != 0)
846+
&& max_fixed_reg < min_limit
837847
{
838848
continue;
839849
}
@@ -867,6 +877,7 @@ impl<'a, F: Function> Env<'a, F> {
867877
// skip this edit.
868878
if !(requires_reg && self.ctx.pregs[preg.index()].is_stack)
869879
&& *first_preg.get_or_insert(preg) == preg
880+
&& preg.hw_enc() < min_limit
870881
{
871882
continue;
872883
}

0 commit comments

Comments
 (0)