Skip to content

ConstraintAnalysis: Track relevant locals#8921

Merged
kripken merged 26 commits into
WebAssembly:mainfrom
kripken:constraint.relevant
Jul 21, 2026
Merged

ConstraintAnalysis: Track relevant locals#8921
kripken merged 26 commits into
WebAssembly:mainfrom
kripken:constraint.relevant

Conversation

@kripken

@kripken kripken commented Jul 20, 2026

Copy link
Copy Markdown
Member

By avoiding work on irrelevant locals - ones we can't prove anything for -
we make the pass 20% faster.

@kripken
kripken requested a review from a team as a code owner July 20, 2026 21:24
@kripken
kripken requested review from tlively and removed request for a team July 20, 2026 21:24
Comment thread src/passes/ConstraintAnalysis.cpp Outdated
// to is relevant as well. We store pairs here of key=source, value=targets.
std::unordered_map<Index, std::vector<Index>> localCopyTargets;

void markRelevant(Expression* curr) {

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.

Suggested change
void markRelevant(Expression* curr) {
void maybeMarkRelevant(Expression* curr) {

Since this does not unconditionally mark the expression relevant.

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.

Comment thread src/passes/ConstraintAnalysis.cpp Outdated
Comment on lines +90 to +92
// Track local copies too, as if one local is relevant, another it is copied
// to is relevant as well. We store pairs here of key=source, value=targets.
std::unordered_map<Index, std::vector<Index>> localCopyTargets;

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.

Shouldn't we be propagating relevance backward from copy destination to copy source? If I have a local $x whose value is never set or compared to anything, then it is copied to relevant $y, then I want to have that initial $x = 0 constraint. In contrast, if I have relevant $y and it is copied to irrelevant $z, then there is no need to consider $z relevant.

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.

Shouldn't we be propagating relevance backward from copy destination to copy source?

Good catch! Yes, the default value is tricky that way. Fixed.

In contrast, if I have relevant $y and it is copied to irrelevant $z, then there is no need to consider $z relevant.

Hmm, I thought that was true due to contradictions, but you're right, I can't make a testcase that shows the problem, good catch as well. Fixed.

Comment thread src/passes/ConstraintAnalysis.cpp Outdated
// happen, but intermediate optimizations can make things become relevant,
// consider this:
//
// x == (y < 10)

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.

Isn't this change not NFC because of this? IIUC, we're losing a very small amount of optimization power here.

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.

Yes, fair enough, I'll remove the NFC. This makes us 20% faster in return for needing another cycle in rare cases.

Co-authored-by: Thomas Lively <tlively123@gmail.com>
@kripken kripken changed the title [NFC] ConstraintAnalysis: Track relevant locals ConstraintAnalysis: Track relevant locals Jul 21, 2026
@kripken
kripken merged commit 108e796 into WebAssembly:main Jul 21, 2026
16 checks passed
@kripken
kripken deleted the constraint.relevant branch July 21, 2026 18:00
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