Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve optimisations on range constraints #4690

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,12 @@ impl Instruction {
Instruction::IncrementRc { .. } => None,
Instruction::DecrementRc { .. } => None,
Instruction::RangeCheck { value, max_bit_size, .. } => {
if let Some(numeric_constant) = dfg.get_numeric_constant(*value) {
if numeric_constant.num_bits() < *max_bit_size {
return Remove;
}
let max_potential_bits = dfg.get_value_max_num_bits(*value);
if max_potential_bits < *max_bit_size {
Remove
} else {
None
}
None
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ pub(super) fn simplify_call(
let max_bit_size = dfg.get_numeric_constant(arguments[1]);
if let Some(max_bit_size) = max_bit_size {
let max_bit_size = max_bit_size.to_u128() as u32;
SimplifyResult::SimplifiedToInstruction(Instruction::RangeCheck {
value,
max_bit_size,
assert_message: Some("call to assert_max_bit_size".to_owned()),
})
let max_potential_bits = dfg.get_value_max_num_bits(value);
if max_potential_bits < max_bit_size {
SimplifyResult::Remove
} else {
SimplifyResult::SimplifiedToInstruction(Instruction::RangeCheck {
value,
max_bit_size,
assert_message: Some("call to assert_max_bit_size".to_owned()),
})
}
} else {
SimplifyResult::None
}
Expand Down
Loading