Skip to content

Heap2Local: reset data structures after optimizing#8857

Merged
tlively merged 4 commits into
mainfrom
heap2local-always-reset
Jun 18, 2026
Merged

Heap2Local: reset data structures after optimizing#8857
tlively merged 4 commits into
mainfrom
heap2local-always-reset

Conversation

@tlively

@tlively tlively commented Jun 18, 2026

Copy link
Copy Markdown
Member

This entirely eliminates the class of bugs due to stale data in the parents and localGraph after a previous allocation has been optimized.

This entirely eliminates the class of bugs due to stale data in the `parents` and `localGraph` after a previous allocation has been optimized.

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this PR is the way to go. It is just too risky to keep such data structures up to date. As optimizing is not super-common here, I think the overhead is probably acceptable.

Comment thread src/passes/Heap2Local.cpp Outdated
localGraph = std::make_unique<LazyLocalGraph>(func, &wasm);
parents = std::make_unique<Parents>(func->body);
branchTargets =
std::make_unique<BranchUtils::BranchTargets>(func->body);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can have a helper for this repeating logic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@tlively tlively marked this pull request as ready for review June 18, 2026 21:12
@tlively tlively requested a review from a team as a code owner June 18, 2026 21:12
@tlively tlively requested review from stevenfontanella and removed request for a team June 18, 2026 21:12
Comment thread test/lit/passes/heap2local-desc.wast Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now we can optimize more, as we notice that we compare to a descriptor created in this function.

(func $cmpxchg-expected-first
(drop
(struct.atomic.rmw.cmpxchg $struct 0
(struct.new_default $struct)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These comments need updating too I think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the comments on this function all still apply. I'll take a look at whether any other changes need corresponding comments updated, though.

@tlively tlively enabled auto-merge (squash) June 18, 2026 22:40

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be worth measuring this on some code. If it is slow, we could do similar things like we do with pop here - only refresh this data if we generate new code that forces that, etc.

@tlively tlively merged commit 87be9bb into main Jun 18, 2026
16 checks passed
@tlively tlively deleted the heap2local-always-reset branch June 18, 2026 23:06
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.

2 participants