Skip to content

Commit 07b07d0

Browse files
authored
fix(ssa refactor): Add missing calls to resolve in Instruction::simplify (#1678)
Fix missing calls to resolve in Instruction::simplify
1 parent 7ce8cce commit 07b07d0

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

crates/noirc_evaluator/src/ssa_refactor/ir/dfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl DataFlowGraph {
308308
&self,
309309
value: ValueId,
310310
) -> Option<(FieldElement, Type)> {
311-
match &self.values[value] {
311+
match &self.values[self.resolve(value)] {
312312
Value::NumericConstant { constant, typ } => Some((*constant, typ.clone())),
313313
_ => None,
314314
}
@@ -320,7 +320,7 @@ impl DataFlowGraph {
320320
&self,
321321
value: ValueId,
322322
) -> Option<(im::Vector<ValueId>, Rc<CompositeType>)> {
323-
match &self.values[value] {
323+
match &self.values[self.resolve(value)] {
324324
// Vectors are shared, so cloning them is cheap
325325
Value::Array { array, element_type } => Some((array.clone(), element_type.clone())),
326326
_ => None,

crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Instruction {
244244
}
245245
}
246246
Instruction::Not(value) => {
247-
match &dfg[*value] {
247+
match &dfg[dfg.resolve(*value)] {
248248
// Limit optimizing ! on constants to only booleans. If we tried it on fields,
249249
// there is no Not on FieldElement, so we'd need to convert between u128. This
250250
// would be incorrect however since the extra bits on the field would not be flipped.
@@ -497,13 +497,13 @@ impl Binary {
497497
}
498498
}
499499
BinaryOp::Eq => {
500-
if self.lhs == self.rhs {
500+
if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) {
501501
let one = dfg.make_constant(FieldElement::one(), Type::bool());
502502
return SimplifyResult::SimplifiedTo(one);
503503
}
504504
}
505505
BinaryOp::Lt => {
506-
if self.lhs == self.rhs {
506+
if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) {
507507
let zero = dfg.make_constant(FieldElement::zero(), Type::bool());
508508
return SimplifyResult::SimplifiedTo(zero);
509509
}
@@ -523,7 +523,7 @@ impl Binary {
523523
}
524524
}
525525
BinaryOp::Xor => {
526-
if self.lhs == self.rhs {
526+
if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) {
527527
let zero = dfg.make_constant(FieldElement::zero(), Type::bool());
528528
return SimplifyResult::SimplifiedTo(zero);
529529
}

crates/noirc_evaluator/src/ssa_refactor/opt/flatten_cfg.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ impl<'f> Context<'f> {
444444
if destination == self.branch_ends[&jmpif_block] {
445445
// If the branch destination is the same as the end of the branch, this must be the
446446
// 'else' case of an if with no else - so there is no else branch.
447-
Branch { condition: new_condition, last_block: jmpif_block, store_values: HashMap::new() }
447+
Branch {
448+
condition: new_condition,
449+
last_block: jmpif_block,
450+
store_values: HashMap::new(),
451+
}
448452
} else {
449453
self.push_condition(jmpif_block, new_condition);
450454
self.insert_current_side_effects_enabled();
@@ -459,7 +463,11 @@ impl<'f> Context<'f> {
459463
self.conditions.pop();
460464
let stores_in_branch = std::mem::replace(&mut self.store_values, old_stores);
461465

462-
Branch { condition: new_condition, last_block: final_block, store_values: stores_in_branch }
466+
Branch {
467+
condition: new_condition,
468+
last_block: final_block,
469+
store_values: stores_in_branch,
470+
}
463471
}
464472
}
465473

0 commit comments

Comments
 (0)