Skip to content

Conversation

@tlively
Copy link
Member

@tlively tlively commented Nov 23, 2024

CodeFolding previously did not consider br_on_* instructions at all, so
it would happily merge tails even if there were br_on_* branches to the
same label with non-matching tails. Fix the bug by making any label
targeted by any instruction not explicitly handled by CodeFolding
unoptimizable. This will gracefully handle other branching instructions
like resume and resume_throw as well. Folding these branches
properly is left as future work.

Also rename the test file from code-folding_enable-threads.wast to just
code-folding.wast and enable all features instead of just threads. The
old name was left over from when the test was originally ported to lit,
and the new feature is necessary because the new test uses GC
instructions.

@tlively tlively requested a review from kripken November 23, 2024 04:29

void visitSwitch(Switch* curr) {
for (auto target : curr->targets) {
unoptimizables.insert(target);
Copy link
Member

Choose a reason for hiding this comment

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

Another option could be to use visitExpression and BranchUtils to rule out all branches but a normal Break, which would avoid special-casing BrOn and Switch. But lgtm as that might not be worth it.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea. That will handle resume and resume_throw as well.

@tlively tlively changed the base branch from code-folding-no-concrete to main November 25, 2024 19:05
@tlively tlively changed the title Take BrOn into account in CodeFolding Handle unoptimized branches in CodeFolding Nov 25, 2024
CodeFolding previously did not consider br_on_* instructions at all, so
it would happily merge tails even if there were br_on_* branches to the
same label with non-matching tails. Fix the bug by making any label
targeted by any instruction not explicitly handled by CodeFolding
unoptimizable. This will gracefully handle other branching instructions
like `resume` and `resume_throw` as well. Folding these branches
properly is left as future work.

Also rename the test file from code-folding_enable-threads.wast to just
code-folding.wast and enable all features instead of just threads. The
old name was left over from when the test was originally ported to lit,
and the new feature is necessary because the new test uses GC
instructions.
@tlively
Copy link
Member Author

tlively commented Nov 25, 2024

Updated the implementation and rebased this onto main so it can land before the more controversial change that prevents concrete If arms from being folded.

@tlively tlively merged commit a2a8d2a into main Nov 25, 2024
13 checks passed
@tlively tlively deleted the code-folding-br-on branch November 25, 2024 20:05
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.

3 participants