Skip to content

Commit

Permalink
Merge pull request #1566 from ltratt/guard_sanity_check
Browse files Browse the repository at this point in the history
Sanity check that optimising guards away can't go wrong.
  • Loading branch information
ptersilie authored Jan 27, 2025
2 parents 01349d5 + 7b2d334 commit 9668e12
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ykrt/src/compile/jitc_yk/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,17 @@ impl Opt {
}

fn opt_guard(&mut self, iidx: InstIdx, inst: GuardInst) -> Result<(), CompilationError> {
if let Operand::Const(_) = self.an.op_map(&self.m, inst.cond(&self.m)) {
if let Operand::Const(cidx) = self.an.op_map(&self.m, inst.cond(&self.m)) {
// A guard that references a constant is, by definition, not needed and
// doesn't affect future analyses.
let Const::Int(_, v) = self.m.const_(cidx) else {
panic!()
};
assert_eq!(v.bitw(), 1);
assert!(
(inst.expect() && v.to_zero_ext_u8().unwrap() == 1)
|| (!inst.expect() && v.to_zero_ext_u8().unwrap() == 0)
);
self.m.replace(iidx, Inst::Tombstone);
} else {
self.an.guard(&self.m, inst);
Expand Down

0 comments on commit 9668e12

Please sign in to comment.