Skip to content

Commit 1b72a17

Browse files
authored
fix(mem2reg): Handle aliases better when setting a known value for a load (#5959)
# Description ## Problem\* Resolves #5771 This was a bug found on AztecProtocol/aztec-packages#8378 from #5935. However it looks to inadvertently fix the linked issue as well. ## Summary\* We were just directly inserting a new expression and alias for a load result. This was overriding whatever expression of AliasSet may have been there before. This PR switches to checking whether the result already has an expression, which if it does to use that. It then checks whether the result already has an alias set, if it does we add to the alias set rather than overriding it. ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1 parent 00a79ce commit 1b72a17

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,19 @@ impl<'f> PerFunctionContext<'f> {
286286
} else {
287287
references.mark_value_used(address, self.inserter.function);
288288

289-
let expression = if let Some(expression) = references.expressions.get(&result) {
290-
expression.clone()
291-
} else {
292-
references.expressions.insert(result, Expression::Other(result));
293-
Expression::Other(result)
294-
};
295-
if let Some(aliases) = references.aliases.get_mut(&expression) {
289+
let expression =
290+
references.expressions.entry(result).or_insert(Expression::Other(result));
291+
// Make sure this load result is marked an alias to itself
292+
if let Some(aliases) = references.aliases.get_mut(expression) {
293+
// If we have an alias set, add to the set
296294
aliases.insert(result);
297295
} else {
296+
// Otherwise, create a new alias set containing just the load result
298297
references
299298
.aliases
300299
.insert(Expression::Other(result), AliasSet::known(result));
301300
}
301+
// Mark that we know a load result is equivalent to the address of a load.
302302
references.set_known_value(result, address);
303303

304304
self.last_loads.insert(address, (instruction, block_id));

0 commit comments

Comments
 (0)