[llvm] AMDGPU/GlobalISel: Regbanklegalize rules for INTRIN_IMAGE (PR #179810)
Petar Avramovic via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 18 06:58:18 PST 2026
================
@@ -1715,3 +1717,74 @@ void RegBankLegalizeHelper::applyMappingTrivial(MachineInstr &MI) {
}
}
}
+
+bool RegBankLegalizeHelper::applyRegisterBanksINTRIN_IMAGE(MachineInstr &MI) {
+ const AMDGPU::RsrcIntrinsic *RSrcIntrin =
+ AMDGPU::lookupRsrcIntrinsic(AMDGPU::getIntrinsicID(MI));
+ assert(RSrcIntrin && RSrcIntrin->IsImage);
+
+ unsigned RsrcIdx = RSrcIntrin->RsrcArg;
+ const unsigned NumDefs = MI.getNumExplicitDefs();
+
+ // The reported argument index is relative to the IR intrinsic call arguments,
+ // so we need to shift by the number of defs and the intrinsic ID.
+ RsrcIdx += NumDefs + 1;
+
+ MachineBasicBlock *MBB = MI.getParent();
+ B.setInsertPt(*MBB, MBB->SkipPHIsAndLabels(std::next(MI.getIterator())));
+
+ // Defs(for image loads with return) are vgpr.
+ for (unsigned i = 0; i < NumDefs; ++i) {
+ const RegisterBank *RB = MRI.getRegBank(MI.getOperand(i).getReg());
+ if (RB == SgprRB) {
+ Register Reg = MI.getOperand(i).getReg();
+ Register NewVgprDst =
+ MRI.createVirtualRegister({VgprRB, MRI.getType(Reg)});
+ MI.getOperand(i).setReg(NewVgprDst);
+ buildReadAnyLane(B, Reg, NewVgprDst, RBI);
+ }
+ }
+
+ B.setInstr(MI);
+
+ // Register uses(before RsrcIdx) are vgpr.
+ for (unsigned i = 1; i < RsrcIdx; ++i) {
+ MachineOperand &Op = MI.getOperand(i);
+ if (!Op.isReg())
+ continue;
+
+ Register Reg = Op.getReg();
+ if (!Reg.isVirtual())
+ continue;
+
+ const RegisterBank *RB = MRI.getRegBank(Reg);
+
+ if (RB != VgprRB) {
+ auto Copy = B.buildCopy({VgprRB, MRI.getType(Reg)}, Reg);
+ Op.setReg(Copy.getReg(0));
----------------
petar-avramovic wrote:
No, think that AMDGPURegisterBankInfo used to call LegalizeHelper for some cases, and it needed a way to set reg bank.
Here when we create new instructions, registers get type and bank.
https://github.com/llvm/llvm-project/pull/179810
More information about the llvm-commits
mailing list