From 3530e41f10a9259d833f563483182a40b1bd81b5 Mon Sep 17 00:00:00 2001 From: guipublic Date: Fri, 13 Oct 2023 09:42:34 +0000 Subject: [PATCH] do not simplify mod,div, unless rhs is constant --- .../noirc_evaluator/src/ssa/ir/instruction.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index f748aa040a1..badc1e82d50 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -239,10 +239,19 @@ impl Instruction { pub(crate) fn has_side_effects(&self, dfg: &DataFlowGraph) -> bool { use Instruction::*; - match self { - Binary(_) - | Cast(_, _) + Binary(binary) => { + if matches!(binary.operator, BinaryOp::Div | BinaryOp::Mod) { + if let Some(rhs) = dfg.get_numeric_constant(binary.rhs) { + rhs == FieldElement::zero() + } else { + true + } + } else { + false + } + } + Cast(_, _) | Not(_) | Truncate { .. } | Allocate