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

fix: don't deduplicate binary math of unsigned types #6848

Merged
merged 9 commits into from
Dec 19, 2024
Merged
21 changes: 16 additions & 5 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
// These can fail.
Constrain(..) | RangeCheck { .. } => true,

// This should never be side-effectful

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

View workflow job for this annotation

GitHub Actions / Code

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

// Some binary math can overflow or underflow
Expand Down Expand Up @@ -556,10 +556,22 @@
/// If true the instruction will depend on `enable_side_effects` context during acir-gen.
pub(crate) fn requires_acir_gen_predicate(&self, dfg: &DataFlowGraph) -> bool {
match self {
Instruction::Binary(binary)
if matches!(binary.operator, BinaryOp::Div | BinaryOp::Mod) =>
{
true
Instruction::Binary(binary) => {
// Some binary math can overflow or underflow
match binary.operator {
asterite marked this conversation as resolved.
Show resolved Hide resolved
BinaryOp::Add
| BinaryOp::Sub
| BinaryOp::Mul
| BinaryOp::Div
| BinaryOp::Mod => true,
BinaryOp::Eq
| BinaryOp::Lt
| BinaryOp::And
| BinaryOp::Or
| BinaryOp::Xor
| BinaryOp::Shl
| BinaryOp::Shr => false,
}
}

Instruction::ArrayGet { array, index } => {
Expand All @@ -577,7 +589,6 @@
_ => false,
},
Instruction::Cast(_, _)
| Instruction::Binary(_)
| Instruction::Not(_)
| Instruction::Truncate { .. }
| Instruction::Constrain(_, _, _)
Expand Down
7 changes: 7 additions & 0 deletions test_programs/execution_success/regression_6834/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_6834"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
2 changes: 2 additions & 0 deletions test_programs/execution_success/regression_6834/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
year = 1
min_age = 1
9 changes: 9 additions & 0 deletions test_programs/execution_success/regression_6834/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main(year: u32, min_age: u8) -> pub u32 {
if min_age == 0 {
(year - 2) / 4
} else if year > 1 {
(year - 2) / 4
} else {
0
}
}
Loading