Skip to content

Commit

Permalink
feat: avoid overflow checks on boolean multiplication (#3745)
Browse files Browse the repository at this point in the history
# Description

## Problem\*


## Summary\*

Currently multiplication of booleans adds in a range check which is
unnecessary as the result cannot be larger than the inputs.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
hayleykwan committed Dec 12, 2023
1 parent 54a1ed5 commit 9b5b686
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ impl<'a> FunctionContext<'a> {
_ => unreachable!("operator {} should not overflow", operator),
};

if operator == BinaryOpKind::ShiftLeft {
if operator == BinaryOpKind::Multiply && bit_size == 1 {
result
} else if operator == BinaryOpKind::ShiftLeft {
self.check_left_shift_overflow(result, rhs, bit_size, location)
} else {
let message = format!("attempt to {} with overflow", op_name);
Expand Down

0 comments on commit 9b5b686

Please sign in to comment.