From c43b9e6777ff49f6babf3670cbd754bfb4b9a340 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 6 Sep 2024 14:40:08 +0000 Subject: [PATCH] handle aliases better when setting a known value for a load --- compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 4d3666bea1a..a1f809bc5c8 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -286,8 +286,17 @@ impl<'f> PerFunctionContext<'f> { } else { references.mark_value_used(address, self.inserter.function); - references.expressions.insert(result, Expression::Other(result)); - references.aliases.insert(Expression::Other(result), AliasSet::known(result)); + let expression = + references.expressions.entry(result).or_insert(Expression::Other(result)); + // Make sure this load result is marked an alias to itself + if let Some(aliases) = references.aliases.get_mut(expression) { + aliases.insert(result); + } else { + references + .aliases + .insert(Expression::Other(result), AliasSet::known(result)); + } + // Mark that we know a load result is equivalent to the address of a load. references.set_known_value(result, address); self.last_loads.insert(address, (instruction, block_id));