Skip to content

Fix SROA miscompilation issues - #7689

Merged
ironcev merged 2 commits into
masterfrom
ironcev/fix-combine-indices-issue
Jul 20, 2026
Merged

Fix SROA miscompilation issues#7689
ironcev merged 2 commits into
masterfrom
ironcev/fix-combine-indices-issue

Conversation

@ironcev

@ironcev ironcev commented Jul 17, 2026

Copy link
Copy Markdown
Member

Description

This PR fixes two miscompilation issues in SROA:

  • GEP pointers coming through block arguments were treated in combine_indices as having a known source access at index 0 (returning empty vector for indices). This is obviously wrong since at run-time the argument can come from any of the predecessor and have an arbitrary, predecessor dependent value.
  • The case of combine_indices returning None and signaling that the source of indices was unknown, wasn't inspected when removing symbols from potential candidates.

The provided tests cover both issues and will fail if any of them regresses.

Fixing these two issues didn't cause any changes in o2 trade-account benchmarks. In some o2 order-book benchmarks there are slight regressions ~0.04% in average and 0.05% max.

Additionally the PR removes reduntant forc build run from the attributes_error_type_and_error test.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev
ironcev temporarily deployed to fuel-sway-bot July 17, 2026 13:32 — with GitHub Actions Inactive
@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes optimizer correctness logic in release builds; wrong handling would miscompile memory accesses, though regressions are covered by new tests and benchmarks reportedly show only minor impact.

Overview
Fixes release-mode SROA miscompiles when aggregate locals are accessed through pointers that reach a join block as non-entry block arguments (e.g. &t.1 vs &t.2 merged in an if).

combine_indices no longer treats every block argument as offset zero: only entry block args (function parameters) contribute no indices; join block args now return None because the pointer offset depends on the predecessor.

SROA candidate filtering now drops locals when combine_indices is None, so aggregates are not scalarised when loads/stores go through those unknown-offset pointers.

Adds Block::is_entry, IR verifier rules that the entry block is named entry (and no other block uses that name), plus IR and e2e regression tests. Trims a duplicate forc build in an unrelated fail-test snapshot.

Reviewed by Cursor Bugbot for commit 9bb4595. Bugbot is set up for automated code reviews on this repo. Configure here.

@ironcev ironcev self-assigned this Jul 17, 2026
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes compiler: optimization IR Optimization Passes labels Jul 17, 2026
@ironcev

ironcev commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

馃憤

@ironcev
ironcev marked this pull request as ready for review July 17, 2026 13:46
@ironcev
ironcev requested a review from a team as a code owner July 17, 2026 13:46
@ironcev
ironcev enabled auto-merge (squash) July 17, 2026 13:47
@ironcev
ironcev requested a review from xgreenx July 17, 2026 14:12
Comment thread sway-ir/src/analysis/memory_utils.rs
Comment thread sway-ir/src/optimize/sroa.rs Outdated
@ironcev
ironcev temporarily deployed to fuel-sway-bot July 17, 2026 19:55 — with GitHub Actions Inactive
@ironcev
ironcev requested review from xgreenx and xunilrj July 17, 2026 20:25
@ironcev
ironcev merged commit 5184c93 into master Jul 20, 2026
41 checks passed
@ironcev
ironcev deleted the ironcev/fix-combine-indices-issue branch July 20, 2026 13:38
ironcev added a commit that referenced this pull request Jul 27, 2026
## Description

This PR rolls out `Block::is_entry`, as discussed in
#7689 (comment).

Additionally, the PR:
- returns `&str` from `Block::get_label`. A new owned `String` was
mostly unnecessary created, because an owned string is needed only for
`IrError`s.
- removes the `VerifyPassesOpts` which is not used since #7672.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: ir IRgen and sway-ir including optimization passes compiler: optimization IR Optimization Passes compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants