-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN #110714
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
Merged
krzysz00
merged 3 commits into
llvm:main
from
krzysz00:fix-buffer-load-store-pointers-gisel
Oct 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5794,8 +5794,9 @@ Register AMDGPULegalizerInfo::handleD16VData(MachineIRBuilder &B, | |
return Reg; | ||
} | ||
|
||
Register AMDGPULegalizerInfo::fixStoreSourceType( | ||
MachineIRBuilder &B, Register VData, bool IsFormat) const { | ||
Register AMDGPULegalizerInfo::fixStoreSourceType(MachineIRBuilder &B, | ||
Register VData, LLT MemTy, | ||
bool IsFormat) const { | ||
MachineRegisterInfo *MRI = B.getMRI(); | ||
LLT Ty = MRI->getType(VData); | ||
|
||
|
@@ -5805,6 +5806,10 @@ Register AMDGPULegalizerInfo::fixStoreSourceType( | |
if (hasBufferRsrcWorkaround(Ty)) | ||
return castBufferRsrcToV4I32(VData, B); | ||
|
||
if (shouldBitcastLoadStoreType(ST, Ty, MemTy) || Ty.isPointerVector()) { | ||
Ty = getBitcastRegisterType(Ty); | ||
VData = B.buildBitcast(Ty, VData).getReg(0); | ||
} | ||
// Fixup illegal register types for i8 stores. | ||
if (Ty == LLT::scalar(8) || Ty == S16) { | ||
Register AnyExt = B.buildAnyExt(LLT::scalar(32), VData).getReg(0); | ||
|
@@ -5822,22 +5827,26 @@ Register AMDGPULegalizerInfo::fixStoreSourceType( | |
} | ||
|
||
bool AMDGPULegalizerInfo::legalizeBufferStore(MachineInstr &MI, | ||
MachineRegisterInfo &MRI, | ||
MachineIRBuilder &B, | ||
LegalizerHelper &Helper, | ||
bool IsTyped, | ||
bool IsFormat) const { | ||
MachineIRBuilder &B = Helper.MIRBuilder; | ||
MachineRegisterInfo &MRI = *B.getMRI(); | ||
|
||
Register VData = MI.getOperand(1).getReg(); | ||
LLT Ty = MRI.getType(VData); | ||
LLT EltTy = Ty.getScalarType(); | ||
const bool IsD16 = IsFormat && (EltTy.getSizeInBits() == 16); | ||
const LLT S32 = LLT::scalar(32); | ||
|
||
VData = fixStoreSourceType(B, VData, IsFormat); | ||
castBufferRsrcArgToV4I32(MI, B, 2); | ||
Register RSrc = MI.getOperand(2).getReg(); | ||
|
||
MachineMemOperand *MMO = *MI.memoperands_begin(); | ||
const int MemSize = MMO->getSize().getValue(); | ||
LLT MemTy = MMO->getMemoryType(); | ||
|
||
VData = fixStoreSourceType(B, VData, MemTy, IsFormat); | ||
|
||
castBufferRsrcArgToV4I32(MI, B, 2); | ||
Register RSrc = MI.getOperand(2).getReg(); | ||
|
||
unsigned ImmOffset; | ||
|
||
|
@@ -5930,10 +5939,13 @@ static void buildBufferLoad(unsigned Opc, Register LoadDstReg, Register RSrc, | |
} | ||
|
||
bool AMDGPULegalizerInfo::legalizeBufferLoad(MachineInstr &MI, | ||
MachineRegisterInfo &MRI, | ||
MachineIRBuilder &B, | ||
LegalizerHelper &Helper, | ||
bool IsFormat, | ||
bool IsTyped) const { | ||
MachineIRBuilder &B = Helper.MIRBuilder; | ||
MachineRegisterInfo &MRI = *B.getMRI(); | ||
GISelChangeObserver &Observer = Helper.Observer; | ||
|
||
// FIXME: Verifier should enforce 1 MMO for these intrinsics. | ||
MachineMemOperand *MMO = *MI.memoperands_begin(); | ||
const LLT MemTy = MMO->getMemoryType(); | ||
|
@@ -5982,9 +5994,21 @@ bool AMDGPULegalizerInfo::legalizeBufferLoad(MachineInstr &MI, | |
// Make addrspace 8 pointers loads into 4xs32 loads here, so the rest of the | ||
// logic doesn't have to handle that case. | ||
if (hasBufferRsrcWorkaround(Ty)) { | ||
Observer.changingInstr(MI); | ||
Ty = castBufferRsrcFromV4I32(MI, B, MRI, 0); | ||
Observer.changedInstr(MI); | ||
Dst = MI.getOperand(0).getReg(); | ||
B.setInsertPt(B.getMBB(), MI); | ||
} | ||
if (shouldBitcastLoadStoreType(ST, Ty, MemTy) || Ty.isPointerVector()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ty.isPointerVector should be redundant here too |
||
Ty = getBitcastRegisterType(Ty); | ||
Observer.changingInstr(MI); | ||
Helper.bitcastDst(MI, Ty, 0); | ||
Observer.changedInstr(MI); | ||
Dst = MI.getOperand(0).getReg(); | ||
B.setInsertPt(B.getMBB(), MI); | ||
} | ||
|
||
LLT EltTy = Ty.getScalarType(); | ||
const bool IsD16 = IsFormat && (EltTy.getSizeInBits() == 16); | ||
const bool Unpacked = ST.hasUnpackedD16VMem(); | ||
|
@@ -7364,17 +7388,17 @@ bool AMDGPULegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper, | |
case Intrinsic::amdgcn_raw_ptr_buffer_store: | ||
case Intrinsic::amdgcn_struct_buffer_store: | ||
case Intrinsic::amdgcn_struct_ptr_buffer_store: | ||
return legalizeBufferStore(MI, MRI, B, false, false); | ||
return legalizeBufferStore(MI, Helper, false, false); | ||
case Intrinsic::amdgcn_raw_buffer_store_format: | ||
case Intrinsic::amdgcn_raw_ptr_buffer_store_format: | ||
case Intrinsic::amdgcn_struct_buffer_store_format: | ||
case Intrinsic::amdgcn_struct_ptr_buffer_store_format: | ||
return legalizeBufferStore(MI, MRI, B, false, true); | ||
return legalizeBufferStore(MI, Helper, false, true); | ||
case Intrinsic::amdgcn_raw_tbuffer_store: | ||
case Intrinsic::amdgcn_raw_ptr_tbuffer_store: | ||
case Intrinsic::amdgcn_struct_tbuffer_store: | ||
case Intrinsic::amdgcn_struct_ptr_tbuffer_store: | ||
return legalizeBufferStore(MI, MRI, B, true, true); | ||
return legalizeBufferStore(MI, Helper, true, true); | ||
case Intrinsic::amdgcn_raw_buffer_load: | ||
case Intrinsic::amdgcn_raw_ptr_buffer_load: | ||
case Intrinsic::amdgcn_raw_atomic_buffer_load: | ||
|
@@ -7383,17 +7407,17 @@ bool AMDGPULegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper, | |
case Intrinsic::amdgcn_struct_ptr_buffer_load: | ||
case Intrinsic::amdgcn_struct_atomic_buffer_load: | ||
case Intrinsic::amdgcn_struct_ptr_atomic_buffer_load: | ||
return legalizeBufferLoad(MI, MRI, B, false, false); | ||
return legalizeBufferLoad(MI, Helper, false, false); | ||
case Intrinsic::amdgcn_raw_buffer_load_format: | ||
case Intrinsic::amdgcn_raw_ptr_buffer_load_format: | ||
case Intrinsic::amdgcn_struct_buffer_load_format: | ||
case Intrinsic::amdgcn_struct_ptr_buffer_load_format: | ||
return legalizeBufferLoad(MI, MRI, B, true, false); | ||
return legalizeBufferLoad(MI, Helper, true, false); | ||
case Intrinsic::amdgcn_raw_tbuffer_load: | ||
case Intrinsic::amdgcn_raw_ptr_tbuffer_load: | ||
case Intrinsic::amdgcn_struct_tbuffer_load: | ||
case Intrinsic::amdgcn_struct_ptr_tbuffer_load: | ||
return legalizeBufferLoad(MI, MRI, B, true, true); | ||
return legalizeBufferLoad(MI, Helper, true, true); | ||
case Intrinsic::amdgcn_raw_buffer_atomic_swap: | ||
case Intrinsic::amdgcn_raw_ptr_buffer_atomic_swap: | ||
case Intrinsic::amdgcn_struct_buffer_atomic_swap: | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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 the Ty.isPointerVector() is redundant, these should be handled under the loadStoreBitcastWorkaround case
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.
It isn't. All the pointers vectors fall to the
Size <= 64
case and so don't get bitcastThere 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.
This sounds like just a bug, and this should be folded into shouldBitcastLoadStoreType. It already tries to handle this case, just too late
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.
Except that a regular G_LOAD or G_STORE can handle vectors of pointers just fine, and moving the condition changes a bunch of tests
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 don't think they do work fine. The buffer cases should behave identically to G_LOAD and G_STORE, and both currently rely on the bitcast legalization.
Based on the 64-bit check, the 128-bit <2 x ptr> cases work. The 64-bit cases, e.g. <2 x ptr addrspace(3)> fail:
https://godbolt.org/z/4vWacff1d
So yes, tests should change and start working