Repository navigation
[AMDGPU][Codegen] Don't incorrectly shrink S_LOAD_DWORDX{16,8}_IMM during remat - #225209
Conversation
|
@llvm/pr-subscribers-backend-amdgpu Author: Lucas Ramirez (lucas-rami) ChangesThis came up after #214725 but is a separate issue.
The added test fails without this patch because of the incorrect one-user check. As a sidenote, I find it surprising that the 3 Files Affected:
The server is unavailable at this time. Please wait a few minutes before you try again. |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
IgWod
left a comment
There was a problem hiding this comment.
Thanks! LGTM, but I'll let someone more familiar with this code to approve it.
Yes, I don't think this was implemented the right way and I had a difficult time extending this to other cases |
|
ping |
|
Sorry for the verbosity but Claude seems to have found a real correctness problem (with a repro and a simple fix): Which callers can reach the new code
After greedy splits the original register, ReproducerSame RUN line as It still fails without
Found by instrumenting the PR's hook to log whenever the use it found was not
Suggested addition to FixRestore the old locality, and keep the PR's whole-function single-use check: if (!UseMO || UseMO->getParent() != &*I ||
UseMO->getSubReg() == AMDGPU::NoSubRegister)
break;With that change on top of the PR:
|
3f25fda to
2e78f37
Compare
|
I think the fix suggested by Claude make sense and I have implemented it. Though it makes me dislike even more the fact that we are doing conditional opcode optimization and value replacing in the rematerialization hook. I will address this in a future patch. |
|
@lucas-rami, I think the opcode change is fine, but the register class change scares me. Looks like it got introduced in #68778 |
| assert(MRI.use_nodbg_empty(DestReg) && "DestReg should have no users yet."); | ||
|
|
||
| // Look for a single use of the register at the insertion point that is also | ||
| // a subreg. |
There was a problem hiding this comment.
We're trying to establish that because of the change in register class later on?
I.e., no users mean we can do whatever we want?
Sounds like a fine workaround but we shouldn't change the register class
There was a problem hiding this comment.
We're trying to establish that because of the change in register class later on? I.e., no users mean we can do whatever we want?
No opcode change happens when there are no users. It only happens when there is a subreg use of the rematerialized register at the insertion point that allows to shrink the load (possibly with a change in constant offset). The original logic did not check whether any other use existed; if there was one that e.g., used the whole register, then the original full-width load would need to be kept around in addition to the narrowed one to serve these lanes, making the rematerialization possibly useless. This interacts badly with callers of reMaterialize which have no consistent view of what the method might do beyond rematerializing the requested instruction.
This PR adds the constraint that the use must be the only one to avoid this situation, but I still think it is a bad idea to have MI-user-based opcode/register class changes because it remains a bit mysterious to the calling code. The somewhat recently added UsedLanes argument is IMO a better way to drive these optimizations as it allows the user to clearly signal whether they are only interested in a subset of the rematerialized register's lanes. At which point callers would be responsible for adjusting uses based on any opcode optimization the hook is capable of doing.
This came up after #214725 but is a separate issue.
SIInstrInfo::reMaterializeshould not shrink the width ofS_LOAD_DWORDX{16,8}_IMMifUsedLanesis the full lanemask, keeping this consistent withS_MOV_64handling after [AMDGPU] Shrink S_MOV_B64 to S_MOV_B32 during rematerialization #184333,The added test fails without this patch because of the incorrect one-user check (the load is shrunk despite the full register width being used).
As a sidenote, I find it surprising that the
reMaterializeoverride performs these opcode changes silently. From name and documentation I would expect it to create an instruction whose def is in the same register class at least. I especially find it weird that forS_LOAD_DWORDX{16,8}_IMMwe check for a single user and modify it directly from the hook. To me this feels like this shouldn't be the role ofreMaterialize. If people agree I can address that in the future.