Skip to content

Commit

Permalink
feat: Remove unnecessary truncation of boolean multiplication (noir-l…
Browse files Browse the repository at this point in the history
…ang#3122)

Co-authored-by: Tom French <git@tomfren.ch>
  • Loading branch information
2 people authored and Sakapoi committed Oct 19, 2023
1 parent 5237c8a commit 4c2aaf0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,15 @@ fn operator_result_max_bit_size_to_truncate(
match op {
Add => Some(std::cmp::max(lhs_bit_size, rhs_bit_size) + 1),
Subtract => Some(std::cmp::max(lhs_bit_size, rhs_bit_size) + 1),
Multiply => Some(lhs_bit_size + rhs_bit_size),
Multiply => {
if lhs_bit_size == 1 || rhs_bit_size == 1 {
// Truncation is unnecessary as multiplication by a boolean value cannot cause an overflow.
None
} else {
Some(lhs_bit_size + rhs_bit_size)
}
}

ShiftLeft => {
if let Some(rhs_constant) = dfg.get_numeric_constant(rhs) {
// Happy case is that we know precisely by how many bits the the integer will
Expand Down

0 comments on commit 4c2aaf0

Please sign in to comment.