[llvm] [AMDGPU][GlobalIsel] Add RegBankLegalize rules and lowering for G_AMDGPU_S_BUFFER_LOAD (PR #192480)
Petar Avramovic via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 10:21:08 PDT 2026
================
@@ -1205,6 +1272,109 @@ bool RegBankLegalizeHelper::lower(MachineInstr &MI,
return lowerSplitTo32Select(MI);
case SplitTo32SExtInReg:
return lowerSplitTo32SExtInReg(MI);
+ case S_BUF_to_BUF: {
+ Register Dst = MI.getOperand(0).getReg();
+ LLT Ty = MRI.getType(Dst);
+ const RegisterBank *RSrcBank = MRI.getRegBank(MI.getOperand(1).getReg());
+ // FIXME: 96-bit case was widened during legalize. We need to narrow it
+ // back here but don't have an MMO.
+ unsigned LoadSize = Ty.getSizeInBits();
+ int NumLoads = 1;
+ if (LoadSize == 256 || LoadSize == 512) {
+ NumLoads = LoadSize / 128;
+ Ty = Ty.divide(NumLoads);
+ }
+ // Use the alignment to ensure that the required offsets will fit into the
+ // immediate offsets.
+ const Align Alignment = NumLoads > 1 ? Align(16 * NumLoads) : Align(1);
+ MachineFunction &MF = B.getMF();
+ Register SOffset;
+ Register VOffset;
+ int64_t ImmOffset = 0;
+ unsigned MMOOffset = setBufferOffsets(B, MI.getOperand(2).getReg(), VOffset,
+ SOffset, ImmOffset, Alignment);
+ // TODO: 96-bit loads were widened to 128-bit results. Shrink the
+ // result if we can, but we need to track an MMO for that.
+ // const unsigned MemSize = (Ty.getSizeInBits() + 7) / 8;
+ const unsigned MemSize = divideCeil(Ty.getSizeInBits(), 8);
+ const DataLayout DL = MF.getDataLayout();
+ Type *IRTy = getTypeForLLT(Ty, MF.getFunction().getContext());
+ const Align MemAlign(DL.getABITypeAlign(IRTy));
+ MachineMemOperand *BaseMMO = MF.getMachineMemOperand(
+ MachinePointerInfo(),
+ MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
+ MachineMemOperand::MOInvariant,
+ MemSize, MemAlign);
----------------
petar-avramovic wrote:
Think that G_AMDGPU_S_BUFFER_LOAD should have MMO, at least from what I tried Legalizer does set MMO and we should use that as a base.
Saw one mir test failing because there was no MMO in mir test, but that should not really be the case
https://github.com/llvm/llvm-project/pull/192480
More information about the llvm-commits
mailing list