Skip to content

Commit

Permalink
fix: do not perform dead instruction elimination on mod,div unless rh…
Browse files Browse the repository at this point in the history
…s is constant (noir-lang#3141)
  • Loading branch information
guipublic authored and Sakapoi committed Oct 19, 2023
1 parent e75869a commit 6bdfd49
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bdfd49

Please sign in to comment.