Skip to content

Make areConsecutiveInputsEqual more precise#8783

Open
tlively wants to merge 1 commit into
mainfrom
fix-consecutive-equal-left-effects
Open

Make areConsecutiveInputsEqual more precise#8783
tlively wants to merge 1 commit into
mainfrom
fix-consecutive-equal-left-effects

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented May 28, 2026

Collect the interfering effects specifically from the expressions that are evaluated in between the LHS and RHS fallthrough values. The previous code overapproximated this by collecting all effects from the LHS and RHS expressions, whether or not the effects were due to subexpressions that would have been evaluated before or after the LHS and RHS values. Also use a direction-aware effect ordering check.

Collect the interfering effects specifically from the expressions that are evaluated in between the LHS and RHS fallthrough values. The previous code overapproximated this by collecting all effects from the LHS and RHS expressions, whether or not the effects were due to subexpressions that would have been evaluated before or after the LHS and RHS values. Also use a direction-aware effect ordering check.
@tlively tlively requested a review from a team as a code owner May 28, 2026 00:54
@tlively tlively requested review from kripken and stevenfontanella and removed request for a team May 28, 2026 00:54
}
if (auto* br = left->dynCast<Break>(); br && br->condition) {
assert(br->value);
interferingEffects.walk(br->condition);
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.

Why is it safe to skip the br's effects?

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.

You mean the branch itself? The branch doesn't matter because if control flow branches away and the parent of the consecutive inputs is not executed, then it doesn't matter how we have optimized it.

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.

It could branch to an intermediate point during the fallthrough. Though as this is a Break, the value is unchanged, unlike a BrOn, so maybe that is safe? But a comment would be good.

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.

Named blocks do not allow fallthrough, so I don't think this can happen. It wouldn't be safe to allow named blocks to have fallthrough because the branch could come from somewhere inside the final fallthrough value. I can add a comment, though.

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.

Oh right, we ignore named blocks in fallthrough. I guess this is safe then.

@tlively
Copy link
Copy Markdown
Member Author

tlively commented May 28, 2026

Fuzzer just passed 100k iterations on this 🎉

// after it, so we need not look for further effects. But there might be
// interfering sets in previous br_if conditions, so we cannot just
// return here.
if (areMatchingTeeAndGet(left, right)) {
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.

Doesn't this have to be checked later, after we computed right's fallthrough?

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 simplest to compute right first.

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, we could do even better by checking that right's fallthrough is the matching get. I'll add a TODO to do that in a follow-up. The old code also did not find right's fallthrough first, so this is not a regression.

(local.tee $temp
(block (result i32)
;; This release store is not ordered before the struct.get, so we know
;; it cannot influence the struct.get's value, so we can optimize.
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
;; it cannot influence the struct.get's value, so we can optimize.
;; it cannot influence the struct.get's value, so we can optimize the
;; cmpxchng to [..]

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