[comgr][hotswap] Emit address-carrying half last when splitting ds_load_2addr_* with dst/addr overlap#3319
Draft
YashDeshpande25 wants to merge 2 commits into
Conversation
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.
When the B0→A0 hotswap splits a ds_load_2addr_* into two single-address ds_load_* instructions, the naive "low half first" emission order corrupts the load if the source address register aliases the destination register window. This makes expandDs2AddrLoad scan the destination window and emit the half that carries the address last, and adds a LIT test covering the full window for both b32 and b64.
The bug & fix
A
ds_load_2addr_*address register may alias its destination tuple — this occurs in real gfx1250 code (e.g. rocThrust emitsds_load_2addr_b64 v[2:5], v2 offset1:1, wherev2is both the address and the low destination pair). The single 2-address instruction is safe because the hardware reads the address once before writing any destination, but the naive low-half-first split overwritesv2before the second load reads it, so that load computes its LDS location from the clobbered register — an intermittent wrong/torn read with no prior test coverage. The fix makesexpandDs2AddrLoadscan the whole destination window, determine which half aliases the address, and emit that address-carrying half last: a singleds_loadreads its address before writing its destination, so it's safe as the final use, while the disjoint half emitted first never touches the address (loads only, overlap only; instruction count/size, trampoline sizing, and thes_wait_dscnt 0drain are unchanged).Original (single 2-address instruction):
Before (buggy):
After (fixed):