[llvm] [AMDGPU] Lower loads and stores for address space 13 (PR #209541)
Gheorghe-Teodor Bercea via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 22:04:38 PDT 2026
================
@@ -379,6 +385,83 @@ bool AMDGPULowerVGPREncoding::runOnMachineInstr(MachineInstr &MI) {
return false;
}
+void AMDGPULowerVGPREncoding::lowerLoadStoreIdx(MachineInstr &MI) {
+ auto &LdSt = cast<AMDGPUMI::VLoadStoreIdxInst>(MI);
+ MachineBasicBlock &BB = *MI.getParent();
+ const DebugLoc &DL = MI.getDebugLoc();
+ const bool IsStore = LdSt.mayStore();
+
+ Register Data = LdSt.getDataOp().getReg();
+ unsigned Offset = LdSt.getOffsetOp().getImm();
+ unsigned NumDwords = LdSt.getBitWidth() / 32;
+
+ // A statically out-of-range offset is undefined behavior; mask it into the
+ // addressable range below rather than emit an invalid register. The AGPRs
+ // that gfx90a+ counts as addressable cannot be named as VGPRs.
+ unsigned DynamicVGPRBlockSize =
+ MI.getMF()->getInfo<SIMachineFunctionInfo>()->getDynamicVGPRBlockSize();
+ unsigned NumAddressableVGPRs =
+ std::min(ST->getAddressableNumArchVGPRs(),
+ ST->getAddressableNumVGPRs(DynamicVGPRBlockSize));
+
+ const bool UseGPRIdxMode = LdSt.isGPRIdx();
+
+ MachineInstr *SetOn = nullptr;
+ if (UseGPRIdxMode) {
+ SetOn = BuildMI(BB, MI, DL, TII->get(AMDGPU::S_SET_GPR_IDX_ON))
+ .add(LdSt.getIdxOp())
+ .addImm(IsStore ? AMDGPU::VGPRIndexMode::DST_ENABLE
+ : AMDGPU::VGPRIndexMode::SRC0_ENABLE)
+ .getInstr();
+ SetOn->getOperand(3).setIsUndef();
+ }
+
+ unsigned Opcode;
+ if (UseGPRIdxMode)
+ Opcode = IsStore ? AMDGPU::V_MOV_B32_indirect_write
+ : AMDGPU::V_MOV_B32_indirect_read;
+ else
+ Opcode =
+ IsStore ? AMDGPU::V_MOVRELD_B32_as_mem : AMDGPU::V_MOVRELS_B32_as_mem;
+
+ // A move touches its base plus the run-time index, which no operand can name,
+ // so the base is undef and the liveness of those registers is not expressed.
+ const RegState DataFlags = IsStore
+ ? getUndefRegState(LdSt.getDataOp().isUndef())
+ : RegState::NoFlags;
+ for (unsigned i = 0; i < NumDwords; ++i) {
+ Register Base = AMDGPU::VGPR0 + ((Offset + i) & (NumAddressableVGPRs - 1));
----------------
doru1004 wrote:
Done, with `getRegister`.
https://github.com/llvm/llvm-project/pull/209541
More information about the llvm-commits
mailing list