[NewOptimizer] Backport reverse affinity changes from #26778 #26918
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.
In #26778, I changed the way that the reverse affinity flag works
in order to support node insertion during compaction. In particular,
I had originally (for ease of implementation primarily) had that flag
simply change which BB an inserted node belongs to (i.e. if that flag
was set and there was a basic block boundary at the insertion site,
the new node would belong to the previous BB). In #26778, I changed
this to instead be a flag of whether to insert before or after a given
instruction. As it turns out, this change is also required for correctness.
Because domsorting can change the notion of "previous instruction" by
moving basic blocks, we had (in rare circumstances) instructions end
up in the wrong BB. Backporting those changes fixes that.