Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
// These can fail.
Constrain(..) | ConstrainNotEqual(..) | RangeCheck { .. } => true,

// This should never be side-effectful

Check warning on line 429 in compiler/noirc_evaluator/src/ssa/ir/instruction.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (effectful)
MakeArray { .. } | Noop => false,

// Some binary math can overflow or underflow
Expand Down Expand Up @@ -1036,7 +1036,7 @@
Instruction::DecrementRc { .. } => None,
Instruction::RangeCheck { value, max_bit_size, .. } => {
let max_potential_bits = dfg.get_value_max_num_bits(*value);
if max_potential_bits < *max_bit_size {
if max_potential_bits <= *max_bit_size {
Remove
} else {
None
Expand Down Expand Up @@ -1472,3 +1472,32 @@
}
}
}

#[cfg(test)]
mod tests {
use crate::ssa::{opt::assert_normalized_ssa_equals, ssa_gen::Ssa};

#[test]
fn removes_range_constraints_on_constants() {
let src = "
acir(inline) fn main f0 {
b0(v0: Field):
range_check Field 0 to 1 bits
range_check Field 1 to 1 bits
range_check Field 255 to 8 bits
range_check Field 256 to 8 bits
return
}
";
let ssa = Ssa::from_str_simplifying(src).unwrap();

let expected = "
acir(inline) fn main f0 {
b0(v0: Field):
range_check Field 256 to 8 bits
return
}
";
assert_normalized_ssa_equals(ssa, expected);
}
}
Loading