Fuzzbug fix: fix some weirdness with BTree iteration inner loop

This commit is contained in:
Chris Fallin
2021-06-01 15:32:12 -07:00
parent 44ca1893c3
commit e49727dc75

View File

@@ -2473,38 +2473,41 @@ impl<'a, F: Function> Env<'a, F> {
// literally the range `range`. // literally the range `range`.
let bundle_ranges = &self.bundles[bundle.index()].ranges; let bundle_ranges = &self.bundles[bundle.index()].ranges;
let from_key = LiveRangeKey::from_range(&bundle_ranges.first().unwrap().range); let from_key = LiveRangeKey::from_range(&bundle_ranges.first().unwrap().range);
let to_key = LiveRangeKey::from_range(&bundle_ranges.last().unwrap().range);
assert!(from_key <= to_key);
let mut preg_range_iter = self.pregs[reg.index()] let mut preg_range_iter = self.pregs[reg.index()]
.allocations .allocations
.btree .btree
.range(from_key..=to_key) .range(from_key..)
.peekable(); .peekable();
log::debug!( log::debug!(
"alloc map for {:?}: {:?}", "alloc map for {:?} in range {:?}..: {:?}",
reg, reg,
from_key,
self.pregs[reg.index()].allocations.btree self.pregs[reg.index()].allocations.btree
); );
for entry in bundle_ranges { 'ranges: for entry in bundle_ranges {
log::debug!(" -> range LR {:?}: {:?}", entry.index, entry.range); log::debug!(" -> range LR {:?}: {:?}", entry.index, entry.range);
let key = LiveRangeKey::from_range(&entry.range); let key = LiveRangeKey::from_range(&entry.range);
'alloc: loop {
log::debug!(" -> PReg range {:?}", preg_range_iter.peek());
// Advance our BTree traversal until it is >= this bundle // Advance our BTree traversal until it is >= this bundle
// range (i.e., skip PReg allocations in the BTree that // range (i.e., skip PReg allocations in the BTree that
// are completely before this bundle range). // are completely before this bundle range).
while preg_range_iter.peek().is_some() && *preg_range_iter.peek().unwrap().0 < key { if preg_range_iter.peek().is_some() && *preg_range_iter.peek().unwrap().0 < key {
log::debug!( log::debug!(
"Skipping PReg range {:?}", "Skipping PReg range {:?}",
preg_range_iter.peek().unwrap().0 preg_range_iter.peek().unwrap().0
); );
preg_range_iter.next(); preg_range_iter.next();
continue 'alloc;
} }
// If there are no more PReg allocations, we're done! // If there are no more PReg allocations, we're done!
if preg_range_iter.peek().is_none() { if preg_range_iter.peek().is_none() {
log::debug!(" -> no more PReg allocations; so no conflict possible!"); log::debug!(" -> no more PReg allocations; so no conflict possible!");
break; break 'ranges;
} }
// If the current PReg range is beyond this range, there is no conflict; continue. // If the current PReg range is beyond this range, there is no conflict; continue.
@@ -2513,7 +2516,7 @@ impl<'a, F: Function> Env<'a, F> {
" -> next PReg allocation is at {:?}; moving to next VReg range", " -> next PReg allocation is at {:?}; moving to next VReg range",
preg_range_iter.peek().unwrap().0 preg_range_iter.peek().unwrap().0
); );
continue; break 'alloc;
} }
// Otherwise, there is a conflict. // Otherwise, there is a conflict.
@@ -2537,6 +2540,7 @@ impl<'a, F: Function> Env<'a, F> {
if max_allowable_cost.is_some() if max_allowable_cost.is_some()
&& max_conflict_weight > max_allowable_cost.unwrap() && max_conflict_weight > max_allowable_cost.unwrap()
{ {
log::debug!(" -> reached high cost, retrying early");
return AllocRegResult::ConflictHighCost; return AllocRegResult::ConflictHighCost;
} }
} }
@@ -2549,6 +2553,7 @@ impl<'a, F: Function> Env<'a, F> {
); );
} }
} }
}
if conflicts.len() > 0 { if conflicts.len() > 0 {
return AllocRegResult::Conflict(conflicts); return AllocRegResult::Conflict(conflicts);