-
Notifications
You must be signed in to change notification settings - Fork 838
Fix swapped mergeIf arguments in no-else case in Dataflow IR #8282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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
| mergeIf(afterIfTrueState, afterIfFalseState, condition, curr, locals); | ||
| } else { | ||
| mergeIf(initialState, afterIfTrueState, condition, curr, locals); | ||
| mergeIf(afterIfTrueState, initialState, condition, curr, locals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the order matter here? I can't figure that out either from the code or from the PR description, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks, looks like mergeIf assumes the first is executed if the condition is true. Makes sense.
I opened #8299 to clarify.
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