Replace all assert! with debug_assert!

This results in a ~6% reduction in instruction count.
This commit is contained in:
Amanieu d'Antras
2022-01-11 03:54:08 +00:00
parent a27f93f01e
commit 74928b83fa
13 changed files with 82 additions and 73 deletions

View File

@@ -199,7 +199,7 @@ impl<'a, F: Function> Env<'a, F> {
// array, then reverse them at the end of
// `compute_liveness()`.
assert!(
debug_assert!(
self.vregs[vreg.index()].ranges.is_empty()
|| range.to
<= self.ranges[self.vregs[vreg.index()]
@@ -235,7 +235,7 @@ impl<'a, F: Function> Env<'a, F> {
// Is contiguous with previously-added range; just extend
// its range and return it.
let lr = self.vregs[vreg.index()].ranges.last().unwrap().index;
assert!(range.to == self.ranges[lr.index()].range.from);
debug_assert!(range.to == self.ranges[lr.index()].range.from);
self.ranges[lr.index()].range.from = range.from;
lr
}
@@ -504,11 +504,11 @@ impl<'a, F: Function> Env<'a, F> {
if src.vreg() != dst.vreg() {
log::trace!(" -> move inst{}: src {} -> dst {}", inst.index(), src, dst);
assert_eq!(src.class(), dst.class());
assert_eq!(src.kind(), OperandKind::Use);
assert_eq!(src.pos(), OperandPos::Early);
assert_eq!(dst.kind(), OperandKind::Def);
assert_eq!(dst.pos(), OperandPos::Late);
debug_assert_eq!(src.class(), dst.class());
debug_assert_eq!(src.kind(), OperandKind::Use);
debug_assert_eq!(src.pos(), OperandPos::Early);
debug_assert_eq!(dst.kind(), OperandKind::Def);
debug_assert_eq!(dst.pos(), OperandPos::Late);
// If both src and dest are pinned, emit the
// move right here, right now.
@@ -1012,7 +1012,7 @@ impl<'a, F: Function> Env<'a, F> {
);
vreg_ranges[operand.vreg().vreg()] = lr;
}
assert!(lr.is_valid());
debug_assert!(lr.is_valid());
log::trace!("Use of {:?} at {:?} -> {:?}", operand, pos, lr,);
@@ -1082,7 +1082,7 @@ impl<'a, F: Function> Env<'a, F> {
// need to update with the final range here.
entry.range = self.ranges[entry.index.index()].range;
// Assert in-order and non-overlapping.
assert!(last.is_none() || last.unwrap() <= entry.range.from);
debug_assert!(last.is_none() || last.unwrap() <= entry.range.from);
last = Some(entry.range.to);
}
}

View File

@@ -52,11 +52,11 @@ impl<'a, F: Function> Env<'a, F> {
// Sanity check: both bundles should contain only ranges with appropriate VReg classes.
for entry in &self.bundles[from.index()].ranges {
let vreg = self.ranges[entry.index.index()].vreg;
assert_eq!(from_rc, self.vreg_regs[vreg.index()].class());
debug_assert_eq!(from_rc, self.vreg_regs[vreg.index()].class());
}
for entry in &self.bundles[to.index()].ranges {
let vreg = self.ranges[entry.index.index()].vreg;
assert_eq!(to_rc, self.vreg_regs[vreg.index()].class());
debug_assert_eq!(to_rc, self.vreg_regs[vreg.index()].class());
}
}
@@ -175,7 +175,7 @@ impl<'a, F: Function> Env<'a, F> {
for i in 0..self.bundles[to.index()].ranges.len() {
let entry = self.bundles[to.index()].ranges[i];
if last_range.is_some() {
assert!(last_range.unwrap() < entry.range);
debug_assert!(last_range.unwrap() < entry.range);
}
last_range = Some(entry.range);
@@ -321,10 +321,10 @@ impl<'a, F: Function> Env<'a, F> {
);
let src_bundle =
self.ranges[self.vregs[src_vreg.vreg()].ranges[0].index.index()].bundle;
assert!(src_bundle.is_valid());
debug_assert!(src_bundle.is_valid());
let dest_bundle =
self.ranges[self.vregs[dst_vreg.vreg()].ranges[0].index.index()].bundle;
assert!(dest_bundle.is_valid());
debug_assert!(dest_bundle.is_valid());
self.merge_bundles(/* from */ dest_bundle, /* to */ src_bundle);
}
}
@@ -339,10 +339,10 @@ impl<'a, F: Function> Env<'a, F> {
from_vreg.index()
);
let to_bundle = self.ranges[self.vregs[to_vreg.index()].ranges[0].index.index()].bundle;
assert!(to_bundle.is_valid());
debug_assert!(to_bundle.is_valid());
let from_bundle =
self.ranges[self.vregs[from_vreg.index()].ranges[0].index.index()].bundle;
assert!(from_bundle.is_valid());
debug_assert!(from_bundle.is_valid());
log::trace!(
" -> from bundle{} to bundle{}",
from_bundle.index(),
@@ -384,9 +384,9 @@ impl<'a, F: Function> Env<'a, F> {
}
let src_bundle = self.ranges[src.index()].bundle;
assert!(src_bundle.is_valid());
debug_assert!(src_bundle.is_valid());
let dest_bundle = self.ranges[dst.index()].bundle;
assert!(dest_bundle.is_valid());
debug_assert!(dest_bundle.is_valid());
self.stats.prog_move_merge_attempt += 1;
if self.merge_bundles(/* from */ dest_bundle, /* to */ src_bundle) {
self.stats.prog_move_merge_success += 1;

View File

@@ -62,7 +62,7 @@ impl<'a, F: Function> Env<'a, F> {
);
match (from_alloc.as_reg(), to_alloc.as_reg()) {
(Some(from), Some(to)) => {
assert_eq!(from.class(), to.class());
debug_assert_eq!(from.class(), to.class());
}
_ => {}
}
@@ -148,9 +148,9 @@ impl<'a, F: Function> Env<'a, F> {
to_vreg: VRegIndex,
kind: HalfMoveKind,
) -> u64 {
assert!(from_block.index() < 1 << 21);
assert!(to_block.index() < 1 << 21);
assert!(to_vreg.index() < 1 << 21);
debug_assert!(from_block.index() < 1 << 21);
debug_assert!(to_block.index() < 1 << 21);
debug_assert!(to_vreg.index() < 1 << 21);
((from_block.index() as u64) << 43)
| ((to_block.index() as u64) << 22)
| ((to_vreg.index() as u64) << 1)
@@ -277,7 +277,7 @@ impl<'a, F: Function> Env<'a, F> {
alloc,
vreg.index()
);
assert_eq!(range.from.pos(), InstPosition::Before);
debug_assert_eq!(range.from.pos(), InstPosition::Before);
self.insert_move(
range.from,
InsertMovePrio::Regular,
@@ -816,7 +816,7 @@ impl<'a, F: Function> Env<'a, F> {
.sort_unstable_by_key(|((_, inst), _)| inst.prev());
let prog_move_srcs = std::mem::replace(&mut self.prog_move_srcs, vec![]);
let prog_move_dsts = std::mem::replace(&mut self.prog_move_dsts, vec![]);
assert_eq!(prog_move_srcs.len(), prog_move_dsts.len());
debug_assert_eq!(prog_move_srcs.len(), prog_move_dsts.len());
for (&((_, from_inst), from_alloc), &((to_vreg, to_inst), to_alloc)) in
prog_move_srcs.iter().zip(prog_move_dsts.iter())
{
@@ -827,9 +827,9 @@ impl<'a, F: Function> Env<'a, F> {
to_alloc,
to_vreg.index(),
);
assert!(from_alloc.is_some());
assert!(to_alloc.is_some());
assert_eq!(from_inst, to_inst.prev());
debug_assert!(from_alloc.is_some());
debug_assert!(to_alloc.is_some());
debug_assert_eq!(from_inst, to_inst.prev());
// N.B.: these moves happen with the *same* priority as
// LR-to-LR moves, because they work just like them: they
// connect a use at one progpoint (move-After) with a def
@@ -933,7 +933,7 @@ impl<'a, F: Function> Env<'a, F> {
for m in moves {
if m.from_alloc.is_reg() && m.to_alloc.is_reg() {
assert_eq!(m.from_alloc.class(), m.to_alloc.class());
debug_assert_eq!(m.from_alloc.class(), m.to_alloc.class());
}
if m.from_alloc == m.to_alloc {
if m.to_vreg.is_some() {
@@ -1020,7 +1020,7 @@ impl<'a, F: Function> Env<'a, F> {
},
);
} else {
assert!(extra_slot.is_some());
debug_assert!(extra_slot.is_some());
self.add_edit(
pos,
prio,
@@ -1093,7 +1093,7 @@ impl<'a, F: Function> Env<'a, F> {
m.to_vreg
);
let action = redundant_moves.process_move(m.from_alloc, m.to_alloc, m.to_vreg);
assert!(action.elide);
debug_assert!(action.elide);
if let Some((alloc, vreg)) = action.def_alloc {
log::trace!(" -> DefAlloc: alloc {} vreg {}", alloc, vreg);
self.add_edit(pos, prio, Edit::DefAlloc { alloc, vreg });
@@ -1122,8 +1122,8 @@ impl<'a, F: Function> Env<'a, F> {
.iter()
.map(|(_, _, _, alloc)| *alloc)
.collect::<Vec<_>>();
assert_eq!(vregs.len(), self.func.block_params(block).len());
assert_eq!(allocs.len(), self.func.block_params(block).len());
debug_assert_eq!(vregs.len(), self.func.block_params(block).len());
debug_assert_eq!(allocs.len(), self.func.block_params(block).len());
for (vreg, alloc) in vregs.into_iter().zip(allocs.into_iter()) {
self.add_edit(
self.cfginfo.block_entry[block.index()],
@@ -1164,7 +1164,7 @@ impl<'a, F: Function> Env<'a, F> {
match &edit {
&Edit::Move { from, to, to_vreg } if from == to && to_vreg.is_none() => return,
&Edit::Move { from, to, .. } if from.is_reg() && to.is_reg() => {
assert_eq!(from.as_reg().unwrap().class(), to.as_reg().unwrap().class());
debug_assert_eq!(from.as_reg().unwrap().class(), to.as_reg().unwrap().class());
}
_ => {}
}

View File

@@ -150,7 +150,7 @@ impl<'a, F: Function> Env<'a, F> {
// Otherwise, there is a conflict.
let preg_key = *preg_range_iter.peek().unwrap().0;
assert_eq!(preg_key, key); // Assert that this range overlaps.
debug_assert_eq!(preg_key, key); // Assert that this range overlaps.
let preg_range = preg_range_iter.next().unwrap().1;
log::trace!(" -> btree contains range {:?} that overlaps", preg_range);
@@ -410,7 +410,7 @@ impl<'a, F: Function> Env<'a, F> {
let spillset = self.bundles[bundle.index()].spillset;
assert!(!self.bundles[bundle.index()].ranges.is_empty());
debug_assert!(!self.bundles[bundle.index()].ranges.is_empty());
// Split point *at* start is OK; this means we peel off
// exactly one use to create a minimal bundle.
let bundle_start = self.bundles[bundle.index()]
@@ -419,9 +419,9 @@ impl<'a, F: Function> Env<'a, F> {
.unwrap()
.range
.from;
assert!(split_at >= bundle_start);
debug_assert!(split_at >= bundle_start);
let bundle_end = self.bundles[bundle.index()].ranges.last().unwrap().range.to;
assert!(split_at < bundle_end);
debug_assert!(split_at < bundle_end);
// Is the split point *at* the start? If so, peel off the
// first use: set the split point just after it, or just
@@ -471,7 +471,7 @@ impl<'a, F: Function> Env<'a, F> {
}
}
assert!(split_at > bundle_start && split_at < bundle_end);
debug_assert!(split_at > bundle_start && split_at < bundle_end);
// We need to find which LRs fall on each side of the split,
// which LR we need to split down the middle, then update the
@@ -516,7 +516,7 @@ impl<'a, F: Function> Env<'a, F> {
// down the middle, replace it with a new LR and chop off the
// end of the same LR in the original list.
if split_at > new_lr_list[0].range.from {
assert_eq!(last_lr_in_old_bundle_idx, first_lr_in_new_bundle_idx);
debug_assert_eq!(last_lr_in_old_bundle_idx, first_lr_in_new_bundle_idx);
let orig_lr = new_lr_list[0].index;
let new_lr = self.create_liverange(CodeRange {
from: split_at,
@@ -749,7 +749,7 @@ impl<'a, F: Function> Env<'a, F> {
// We have to split right away. We'll find a point to
// split that would allow at least the first half of the
// split to be conflict-free.
assert!(
debug_assert!(
!self.minimal_bundle(bundle),
"Minimal bundle with conflict!"
);
@@ -932,7 +932,7 @@ impl<'a, F: Function> Env<'a, F> {
);
// If we reach here, we *must* have an option either to split or evict.
assert!(
debug_assert!(
lowest_cost_split_conflict_cost.is_some()
|| lowest_cost_evict_conflict_cost.is_some()
);