Skip to content

Conversation

asterite
Copy link
Collaborator

@asterite asterite commented Aug 25, 2025

Description

Problem

Fixes #9468

Summary

Trying to apply #9613 once more, but fixing an issue.

First issue

I think the refactor in #9613 was fine except: get_known_value was changed to get an address' value regardless of whether the address has aliases.

This get_known_value method is only used in one place: when analyzing Load instructions. There, if get_known_value returned None we did this:

// We don't know the exact value of the address, so we must keep the stores to it.
references.mark_value_used(address, self.inserter.function);

That was actually "because the address might be aliased we better keep the stores to it". That is, because get_known_value implied both that the address didn't have aliases while having a known value, it returning None potentially meant that it was aliased. Now that get_known_value is not related to aliases it's not okay to do that if the value is unknown.

Instead, we must preserve stores to the address if the address is potentially aliased, which is what this PR does (so it's further separating the two concepts).

Second issue

get_known_value retrieving a known value even if an address is aliases, combined with issue #9638, triggered a bug. That was then fixed by #9640

Third issue

The fix above worked because get_known_value returned nothing if an address has an alias. So in this code:

acir(inline) fn create_note f0 {
  b0(v0: &mut Field, v1: &mut Field):
    jmp b1(v0, v1)
  b1(v2: &mut Field, v3: &mut Field):
    store Field 2 at v2
    store Field 3 at v3
    v4 = load v2 -> Field
    return v4
}

with the second issue fix we end up with v2 being aliased to v0, and v3 being aliased to v1.
Then load v2 cannot be simplified because it doesn't have a known value (well, it has, but the code in master returns None if it has aliases).

Now that get_known_value does return a value even if it has aliases, the code above breaks.
The issue is that we set v0 as an alias of v2, but we don't also set the aliases of v0 to be aliases of v2. That is, v2 should be aliased to v0 and v1. That's what the last commit does. It doesn't seem to introduce regressions, and in fact this PR is an optimization.

Additional Context

With these three fixes, CI on Aztec-Packages is green: AztecProtocol/aztec-packages#16576 🎉

Documentation

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@asterite asterite changed the title Reapply "feat(mem2reg): address last known value is independent of its aliases (#9613)" feat(mem2reg): address last known value is independent of its aliases (take two) Aug 25, 2025
Copy link
Contributor

github-actions bot commented Aug 25, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 9e3a8684f63f4a5d7c9d89e5e085691e9039d814, compared to commit: 7c31a63b4688b4bb22e83cdb9639881119343264

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
regression_9455_inliner_max -3 ✅ -6.67%
regression_9455_inliner_min -3 ✅ -6.67%
regression_9455_inliner_zero -3 ✅ -6.67%

Full diff report 👇
Program Brillig opcodes (+/-) %
uhashmap_inliner_min 174,325 (-97) -0.06%
uhashmap_inliner_zero 164,271 (-97) -0.06%
hashmap_inliner_min 79,931 (-57) -0.07%
hashmap_inliner_zero 71,462 (-57) -0.08%
regression_6674_2_inliner_min 863 (-1) -0.12%
regression_6674_3_inliner_min 1,531 (-2) -0.13%
regression_9303_inliner_max 159 (-2) -1.24%
regression_9303_inliner_min 159 (-2) -1.24%
regression_9303_inliner_zero 159 (-2) -1.24%
regression_9439_inliner_max 116 (-3) -2.52%
regression_9439_inliner_min 116 (-3) -2.52%
regression_9439_inliner_zero 116 (-3) -2.52%
regression_9455_inliner_max 42 (-3) -6.67%
regression_9455_inliner_min 42 (-3) -6.67%
regression_9455_inliner_zero 42 (-3) -6.67%

Copy link
Contributor

github-actions bot commented Aug 25, 2025

Changes to Brillig bytecode sizes

Generated at commit: 9e3a8684f63f4a5d7c9d89e5e085691e9039d814, compared to commit: 7c31a63b4688b4bb22e83cdb9639881119343264

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
regression_9439_inliner_max -5 ✅ -3.36%
regression_9439_inliner_min -5 ✅ -3.36%
regression_9439_inliner_zero -5 ✅ -3.36%
regression_9455_inliner_max -5 ✅ -9.62%
regression_9455_inliner_min -5 ✅ -9.62%
regression_9455_inliner_zero -5 ✅ -9.62%

Full diff report 👇
Program Brillig opcodes (+/-) %
hashmap_inliner_min 9,334 (-1) -0.01%
hashmap_inliner_zero 7,976 (-1) -0.01%
uhashmap_inliner_min 7,431 (-3) -0.04%
uhashmap_inliner_zero 6,945 (-3) -0.04%
reference_counts_inliner_0_inliner_min 1,041 (-3) -0.29%
reference_counts_inliner_min_inliner_min 1,041 (-3) -0.29%
reference_counts_inliner_max_inliner_min 1,041 (-3) -0.29%
regression_6674_3_inliner_min 672 (-2) -0.30%
reference_counts_inliner_max_inliner_zero 890 (-3) -0.34%
reference_counts_inliner_0_inliner_zero 890 (-3) -0.34%
reference_counts_inliner_min_inliner_zero 890 (-3) -0.34%
regression_6674_2_inliner_min 243 (-1) -0.41%
reference_counts_slices_inliner_0_inliner_zero 994 (-7) -0.70%
reference_counts_slices_inliner_0_inliner_min 1,201 (-11) -0.91%
regression_9303_inliner_max 105 (-1) -0.94%
regression_9303_inliner_min 105 (-1) -0.94%
regression_9303_inliner_zero 105 (-1) -0.94%
regression_9439_inliner_max 144 (-5) -3.36%
regression_9439_inliner_min 144 (-5) -3.36%
regression_9439_inliner_zero 144 (-5) -3.36%
regression_9455_inliner_max 47 (-5) -9.62%
regression_9455_inliner_min 47 (-5) -9.62%
regression_9455_inliner_zero 47 (-5) -9.62%

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: e5894e6 Previous: c6835b5 Ratio
test_report_zkpassport_noir-ecdsa_ 3 s 1 s 3

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@asterite
Copy link
Collaborator Author

It still fails on Aztec Packages... I'll maybe try again tomorrow.

@asterite asterite closed this Aug 25, 2025
@asterite asterite reopened this Aug 26, 2025
@asterite
Copy link
Collaborator Author

Reopening because I'll try to fix the issue in this PR

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Compilation Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: afb9ae0 Previous: 3629a25 Ratio
private-kernel-reset 10.284 s 7.78 s 1.32

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: afb9ae0 Previous: 3629a25 Ratio
sha512-100-bytes 0.133 s 0.1 s 1.33

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@asterite asterite changed the title feat(mem2reg): address last known value is independent of its aliases (take two) feat(mem2reg): address last known value is independent of its aliases (take three) Aug 26, 2025
@asterite asterite requested a review from a team August 27, 2025 12:05
@asterite
Copy link
Collaborator Author

This is now ready for review. CI is green and this PR in Aztec-Packages is green too (AztecProtocol/aztec-packages#16576).

@jfecher jfecher added this pull request to the merge queue Aug 27, 2025
Merged via the queue into master with commit 46e3595 Aug 27, 2025
126 checks passed
@jfecher jfecher deleted the ab/revert-9628 branch August 27, 2025 13:08
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Aug 28, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: make Ord for slices lexicographic (elements first, then length)
(noir-lang/noir#9555)
chore(ssa): Refactor `unrolling`
(noir-lang/noir#9653)
chore(docs): Update dependency page's examples
(noir-lang/noir#9634)
fix(ssa): Constant fold Brillig calls using the SSA interpreter
(noir-lang/noir#9655)
chore: LICM refactors (noir-lang/noir#9642)
chore: add test for trait bound on implementing type
(noir-lang/noir#9652)
chore: pass `DataFlowGraph` instead of `Function` as arg
(noir-lang/noir#9656)
feat: Group one audit tests
(noir-lang/noir#9445)
fix(expand): better handling of dereferences (again)
(noir-lang/noir#9654)
feat(mem2reg): address last known value is independent of its aliases
(take three) (noir-lang/noir#9633)
chore: remove handling for slice arguments to MSM
(noir-lang/noir#9648)
fix: validate binary operations which do not allow fields
(noir-lang/noir#9649)
END_COMMIT_OVERRIDE
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Aug 28, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: make Ord for slices lexicographic (elements first, then length)
(noir-lang/noir#9555)
chore(ssa): Refactor `unrolling`
(noir-lang/noir#9653)
chore(docs): Update dependency page's examples
(noir-lang/noir#9634)
fix(ssa): Constant fold Brillig calls using the SSA interpreter
(noir-lang/noir#9655)
chore: LICM refactors (noir-lang/noir#9642)
chore: add test for trait bound on implementing type
(noir-lang/noir#9652)
chore: pass `DataFlowGraph` instead of `Function` as arg
(noir-lang/noir#9656)
feat: Group one audit tests
(noir-lang/noir#9445)
fix(expand): better handling of dereferences (again)
(noir-lang/noir#9654)
feat(mem2reg): address last known value is independent of its aliases
(take three) (noir-lang/noir#9633)
chore: remove handling for slice arguments to MSM
(noir-lang/noir#9648)
fix: validate binary operations which do not allow fields
(noir-lang/noir#9649)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mem2reg: Trivial store/load to reference returned from array not resolved
2 participants