Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 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
15 changes: 11 additions & 4 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ impl DataFlowGraph {
return InsertInstructionResult::InstructionRemoved;
}

match simplify(&instruction, self, block, ctrl_typevars.clone(), call_stack) {
let simplify_result =
simplify(&instruction, self, block, ctrl_typevars.clone(), call_stack);

match simplify_result {
SimplifyResult::SimplifiedTo(simplification) => {
InsertInstructionResult::SimplifiedTo(simplification)
}
Expand All @@ -315,8 +318,12 @@ impl DataFlowGraph {
result @ (SimplifyResult::SimplifiedToInstruction(_)
| SimplifyResult::SimplifiedToInstructionMultiple(_)
| SimplifyResult::None) => {
let instructions = result.instructions();
if instructions.is_none() {
let is_simplified = match &result {
SimplifyResult::SimplifiedToInstruction(i) => *i != instruction,
SimplifyResult::None => false,
_ => true,
};
if !is_simplified {
if let Some(id) = existing_id {
if self[id] == instruction {
// Just (re)insert into the block, no need to redefine.
Expand All @@ -328,7 +335,7 @@ impl DataFlowGraph {
}
}
}
let mut instructions = instructions.unwrap_or(vec![instruction]);
let mut instructions = result.instructions().unwrap_or(vec![instruction]);
assert!(
!instructions.is_empty(),
"`SimplifyResult::SimplifiedToInstructionMultiple` must not return empty vector"
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) use call::constant_to_radix;

/// Contains the result to Instruction::simplify, specifying how the instruction
/// should be simplified.
#[derive(Debug)]
pub(crate) enum SimplifyResult {
/// Replace this function's result with the given value
SimplifiedTo(ValueId),
Expand Down
Loading
Loading