Fix swapped mergeIf arguments in no-else case in Dataflow IR#8282
Merged
tlively merged 1 commit intoWebAssembly:mainfrom Feb 11, 2026
Merged
Fix swapped mergeIf arguments in no-else case in Dataflow IR#8282tlively merged 1 commit intoWebAssembly:mainfrom
tlively merged 1 commit intoWebAssembly:mainfrom
Conversation
tlively
reviewed
Feb 10, 2026
…mbly#8273) In doVisitIf, when an if has no else branch, the two state arguments passed to mergeIf were in the wrong order. This caused the phi node to pair the "condition true" value with the initial state and the "condition false" value with the after-if-true state.
fd1ca06 to
dfb28a2
Compare
tlively
approved these changes
Feb 11, 2026
kripken
reviewed
Feb 11, 2026
| mergeIf(afterIfTrueState, afterIfFalseState, condition, curr, locals); | ||
| } else { | ||
| mergeIf(initialState, afterIfTrueState, condition, curr, locals); | ||
| mergeIf(afterIfTrueState, initialState, condition, curr, locals); |
Member
There was a problem hiding this comment.
Why does the order matter here? I can't figure that out either from the code or from the PR description, sorry.
Member
There was a problem hiding this comment.
I think it's so that the phi value indices are the same for the ifTrue and ifFalse edges in both the if-end and if-else-end cases.
Member
There was a problem hiding this comment.
I see, thanks, looks like mergeIf assumes the first is executed if the condition is true. Makes sense.
I opened #8299 to clarify.
kripken
added a commit
to kripken/binaryen
that referenced
this pull request
Feb 11, 2026
kripken
added a commit
to kripken/binaryen
that referenced
this pull request
Feb 11, 2026
kripken
added a commit
that referenced
this pull request
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mergeIfarguments indoVisitIfwhen anifhas noelsebranchFixes #8273.
In the no-else case,
mergeIf(initialState, afterIfTrueState, ...)incorrectly paired the initial state (before the if body ran) with theifTruecondition and the after-if-true state with theifFalsecondition. The fix swaps the arguments tomergeIf(afterIfTrueState, initialState, ...), matching the convention used in the if-with-else case.Test plan
DataflowTest.IfNoElseMergeOrderGTest that builds a dataflow graph for an if-no-else function and verifies the phi node selects the correct values for each branch