Skip to content

fix(Heap2Local): Track RMW results to handle nested flows (#8850) - #9081

Closed
ArkadySkv wants to merge 1 commit into
WebAssembly:mainfrom
ArkadySkv:fix-heap2local-rmw-tracking-8850
Closed

ArkadySkv wants to merge 1 commit into
WebAssembly:mainfrom
ArkadySkv:fix-heap2local-rmw-tracking-8850

Conversation

@ArkadySkv

@ArkadySkv ArkadySkv commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a bug in Heap2Local where nested atomic RMW operations
were incorrectly optimized.

When an inner cmpxchg result flows into the value operand of an outer
xchg, the pass now correctly tracks this data flow and preserves the
RMW operations while localizing their ref operands.

The fix adds RMW result tracking infrastructure (RMWResultInfo) and
extends EscapeAnalyzer, visitStructRMW, and visitStructCmpxchg
to handle nested flows.

Tested with:

All tests pass (4 d8-related failures are unrelated and due to local
environment).

Fixes #8850.

…y#8850)

Add RMW result tracking infrastructure to handle cases where an inner
cmpxchg result flows into the value operand of an outer xchg.

- Add RMWResultInfo struct and RMWResultInfoMap
- Extend EscapeAnalyzer to follow RMW result flows
- Modify visitStructRMW and visitStructCmpxchg to detect nested flows
- Store reference-typed RMW results in scratch locals for downstream use

Fixes WebAssembly#8850.
@ArkadySkv
ArkadySkv requested a review from a team as a code owner September 7, 2026 11:22
@ArkadySkv
ArkadySkv requested review from stevenfontanella and removed request for a team September 7, 2026 11:22
@kripken
kripken requested review from tlively and removed request for stevenfontanella September 8, 2026 18:04
@tlively

tlively commented Sep 9, 2026

Copy link
Copy Markdown
Member

Was this bug not already fixed by #8857?

@ArkadySkv

Copy link
Copy Markdown
Contributor Author

@tlively, Given the diff shows only CHECK line changes, here is the honest reply. It preserves the structure of what you prepared but corrects the claim.

Thanks for the question. I looked into this more carefully and the picture is different from what I assumed when I opened the PR.

I compared the test file on main and on this branch:

git show main:test/lit/passes/heap2local-rmw.wast > /tmp/main.wast
git show fix-heap2local-rmw-tracking-8850:test/lit/passes/heap2local-rmw.wast > /tmp/pr.wast
diff /tmp/main.wast /tmp/pr.wast

The only differences are in ;; CHECK: lines. No new test cases were added on the branch that are not already on main.

I also ran the nested RMW reproducer on both branches:

./bin/wasm-opt nested-rmw.wast --heap2local --fuzz-exec -all

The fuzz-exec self-check — which runs the module before and after optimization and compares the results — passes on both main and this branch. The output is identical. So main already handles the nested case correctly.

You were right in your original question.#8857 did cover this, and the Heap2Local.cpp changes here do not change the execution behaviour of the nested pattern. What they do change is the IR shape, which is why the CHECK lines needed updating.

Since main already handles the nested case, I will close this PR. The Heap2Local.cpp changes add tracking infrastructure that does not change behaviour on any input I have tested, so it is not worth carrying. Sorry for the noise — I should have verified against main first.

@tlively tlively closed this Sep 14, 2026
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.

Heap2Local bug on cmpxchng

2 participants