Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use noirc_errors::call_stack::CallStackId;
use serde::{Deserialize, Serialize};
use std::hash::{Hash, Hasher};

use acvm::acir::{BlackBoxFunc, circuit::ErrorSelector};
use acvm::{
AcirField,
acir::{BlackBoxFunc, circuit::ErrorSelector},
};
use fxhash::FxHasher64;
use iter_extended::vecmap;
use noirc_frontend::hir_def::types::Type as HirType;
Expand Down Expand Up @@ -438,13 +441,17 @@ impl Instruction {
// This should never be side-effectual
MakeArray { .. } | Noop => false,

// Some binary math can overflow or underflow
// Some binary math can overflow or underflow.
Binary(binary) => match binary.operator {
BinaryOp::Add { unchecked: false }
| BinaryOp::Sub { unchecked: false }
| BinaryOp::Mul { unchecked: false }
| BinaryOp::Div
| BinaryOp::Mod => true,
| BinaryOp::Mul { unchecked: false } => {
let typ = dfg.type_of_value(binary.lhs);
!matches!(typ, Type::Numeric(NumericType::NativeField))
}
BinaryOp::Div | BinaryOp::Mod => {
dfg.get_numeric_constant(binary.rhs).is_none_or(|c| c.is_zero())
}
BinaryOp::Add { unchecked: true }
| BinaryOp::Sub { unchecked: true }
| BinaryOp::Mul { unchecked: true }
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub fn primary_passes(options: &SsaEvaluatorOptions) -> Vec<SsaPass> {
SsaPass::new(Ssa::mem2reg, "Mem2Reg"),
// Removing unreachable instructions before DIE, so it gets rid of loads that mem2reg couldn't,
// if they are unreachable and would cause the DIE post-checks to fail.
// This has to be done after flattening, as it destroys the CFG by removing terminators.
SsaPass::new(Ssa::remove_unreachable_instructions, "Remove Unreachable Instructions")
.and_then(Ssa::remove_unreachable_functions),
SsaPass::new(Ssa::dead_instruction_elimination, "Dead Instruction Elimination"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,21 @@ impl Function {
context.remove_current_instruction();
return;
}
active_condition = *condition;

// If we're seeing an `enable_side_effects u1 1` then we want to insert it immediately.
// This is because we want to maximize the effect it will have.
let condition_is_one = context
.dfg
.get_numeric_constant(*condition)
.is_some_and(|condition| condition.is_one());

if condition_is_one {
last_side_effects_enabled_instruction = None;
active_condition = *condition;
return;
} else {
last_side_effects_enabled_instruction = Some(instruction_id);
context.remove_current_instruction();
}

last_side_effects_enabled_instruction = Some(instruction_id);
active_condition = *condition;
context.remove_current_instruction();
return;
}

Expand Down
Loading
Loading