Skip to content

Commit

Permalink
fix(mem2reg): Handle aliases better when setting a known value for a …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
vezenovm authored Sep 6, 2024
1 parent 00a79ce commit 1b72a17
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,19 @@ impl<'f> PerFunctionContext<'f> {
} else {
references.mark_value_used(address, self.inserter.function);

let expression = if let Some(expression) = references.expressions.get(&result) {
expression.clone()
} else {
references.expressions.insert(result, Expression::Other(result));
Expression::Other(result)
};
if let Some(aliases) = references.aliases.get_mut(&expression) {
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) {
// If we have an alias set, add to the set
aliases.insert(result);
} else {
// Otherwise, create a new alias set containing just the load result
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));
Expand Down

0 comments on commit 1b72a17

Please sign in to comment.