Skip to content

Commit b66084a

Browse files
rampitecshiltian
andauthored
[AMDGPU] Verify asm VGPR alignment on gfx1250 (#149880)
Co-authored-by: Shilei Tian <[email protected]>
1 parent 520398e commit b66084a

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5139,13 +5139,45 @@ bool AMDGPUAsmParser::validateAGPRLdSt(const MCInst &Inst) const {
51395139

51405140
bool AMDGPUAsmParser::validateVGPRAlign(const MCInst &Inst) const {
51415141
auto FB = getFeatureBits();
5142+
if (!FB[AMDGPU::FeatureGFX90AInsts] && !FB[AMDGPU::FeatureGFX1250Insts])
5143+
return true;
5144+
51425145
unsigned Opc = Inst.getOpcode();
5146+
const MCRegisterInfo *MRI = getMRI();
51435147
// DS_READ_B96_TR_B6 is the only DS instruction in GFX950, that allows
51445148
// unaligned VGPR. All others only allow even aligned VGPRs.
5145-
if (!(FB[AMDGPU::FeatureGFX90AInsts]) || Opc == AMDGPU::DS_READ_B96_TR_B6_vi)
5149+
if (FB[AMDGPU::FeatureGFX90AInsts] && Opc == AMDGPU::DS_READ_B96_TR_B6_vi)
51465150
return true;
51475151

5148-
const MCRegisterInfo *MRI = getMRI();
5152+
if (FB[AMDGPU::FeatureGFX1250Insts]) {
5153+
switch (Opc) {
5154+
default:
5155+
break;
5156+
case AMDGPU::DS_LOAD_TR6_B96:
5157+
case AMDGPU::DS_LOAD_TR6_B96_gfx12:
5158+
// DS_LOAD_TR6_B96 is the only DS instruction in GFX1250, that
5159+
// allows unaligned VGPR. All others only allow even aligned VGPRs.
5160+
return true;
5161+
case AMDGPU::GLOBAL_LOAD_TR6_B96:
5162+
case AMDGPU::GLOBAL_LOAD_TR6_B96_gfx1250: {
5163+
// GLOBAL_LOAD_TR6_B96 is the only GLOBAL instruction in GFX1250, that
5164+
// allows unaligned VGPR for vdst, but other operands still only allow
5165+
// even aligned VGPRs.
5166+
int VAddrIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::vaddr);
5167+
if (VAddrIdx != -1) {
5168+
const MCOperand &Op = Inst.getOperand(VAddrIdx);
5169+
MCRegister Sub = MRI->getSubReg(Op.getReg(), AMDGPU::sub0);
5170+
if ((Sub - AMDGPU::VGPR0) & 1)
5171+
return false;
5172+
}
5173+
return true;
5174+
}
5175+
case AMDGPU::GLOBAL_LOAD_TR6_B96_SADDR:
5176+
case AMDGPU::GLOBAL_LOAD_TR6_B96_SADDR_gfx1250:
5177+
return true;
5178+
}
5179+
}
5180+
51495181
const MCRegisterClass &VGPR32 = MRI->getRegClass(AMDGPU::VGPR_32RegClassID);
51505182
const MCRegisterClass &AGPR32 = MRI->getRegClass(AMDGPU::AGPR_32RegClassID);
51515183
for (unsigned I = 0, E = Inst.getNumOperands(); I != E; ++I) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1250 -show-encoding %s 2>&1 | FileCheck --check-prefix=GFX1250-ERR --implicit-check-not=error: --strict-whitespace %s
2+
3+
global_load_b96 v[1:3], v[0:1], off
4+
// GFX1250-ERR: :[[@LINE-1]]:{{[0-9]+}}: error: invalid register class: vgpr tuples must be 64 bit aligned

llvm/test/MC/AMDGPU/gfx1250_asm_vop2_err.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1250 -show-encoding %s 2>&1 | FileCheck --check-prefix=GFX1250-ERR --implicit-check-not=error: --strict-whitespace %s
22

3+
v_add_f64 v[1:2], v[1:2], v[1:2]
4+
// GFX1250-ERR: :[[@LINE-1]]:{{[0-9]+}}: error: invalid register class: vgpr tuples must be 64 bit aligned
5+
36
v_fmaak_f32 v4, v2, v6, 3 row_share:1
47
// GFX1250-ERR: :[[@LINE-1]]:{{[0-9]+}}: error: not a valid operand.
58
// GFX1250-ERR-NEXT:{{^}}v_fmaak_f32 v4, v2, v6, 3 row_share:1

0 commit comments

Comments
 (0)