Skip to content

Commit

Permalink
[AMDGPU][MC][GFX10] Corrected constant bus limit for 64-bit shift ins…
Browse files Browse the repository at this point in the history
…tructions

See bug 42744: https://bugs.llvm.org/show_bug.cgi?id=42744

Reviewers: atamazov, arsenm

Differential Revision: https://reviews.llvm.org/D65228

llvm-svn: 370652
  • Loading branch information
dpreobra committed Sep 2, 2019
1 parent a1ad72c commit fe2ee4c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
27 changes: 23 additions & 4 deletions llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool validateOpSel(const MCInst &Inst);
bool validateVccOperand(unsigned Reg) const;
bool validateVOP3Literal(const MCInst &Inst) const;
unsigned getConstantBusLimit(unsigned Opcode) const;
bool usesConstantBus(const MCInst &Inst, unsigned OpIdx);
bool isInlineConstant(const MCInst &Inst, unsigned OpIdx) const;
unsigned findImplicitSGPRReadInVOP(const MCInst &Inst) const;
Expand Down Expand Up @@ -2703,6 +2704,27 @@ bool AMDGPUAsmParser::isInlineConstant(const MCInst &Inst,
}
}

unsigned AMDGPUAsmParser::getConstantBusLimit(unsigned Opcode) const {
if (!isGFX10())
return 1;

switch (Opcode) {
// 64-bit shift instructions can use only one scalar value input
case AMDGPU::V_LSHLREV_B64:
case AMDGPU::V_LSHLREV_B64_gfx10:
case AMDGPU::V_LSHL_B64:
case AMDGPU::V_LSHRREV_B64:
case AMDGPU::V_LSHRREV_B64_gfx10:
case AMDGPU::V_LSHR_B64:
case AMDGPU::V_ASHRREV_I64:
case AMDGPU::V_ASHRREV_I64_gfx10:
case AMDGPU::V_ASHR_I64:
return 1;
default:
return 2;
}
}

bool AMDGPUAsmParser::usesConstantBus(const MCInst &Inst, unsigned OpIdx) {
const MCOperand &MO = Inst.getOperand(OpIdx);
if (MO.isImm()) {
Expand Down Expand Up @@ -2788,10 +2810,7 @@ bool AMDGPUAsmParser::validateConstantBusLimitations(const MCInst &Inst) {
}
ConstantBusUseCount += NumLiterals;

if (isGFX10())
return ConstantBusUseCount <= 2;

return ConstantBusUseCount <= 1;
return ConstantBusUseCount <= getConstantBusLimit(Opcode);
}

bool AMDGPUAsmParser::validateEarlyClobberLimitations(const MCInst &Inst) {
Expand Down
14 changes: 13 additions & 1 deletion llvm/test/MC/AMDGPU/gfx10-constant-bus.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: not llvm-mc -arch=amdgcn -mcpu=gfx1010 -show-encoding %s 2>&1 | FileCheck -check-prefix=GFX10-ERR %s

//-----------------------------------------------------------------------------------------
// On GFX10 we can use two scalar operands
// On GFX10 we can use two scalar operands (except for 64-bit shift instructions)

v_add_f32 v0, s0, s1
// GFX10: v_add_f32_e64 v0, s0, s1 ; encoding: [0x00,0x00,0x03,0xd5,0x00,0x02,0x00,0x00]
Expand All @@ -13,6 +13,15 @@ v_madak_f32 v0, s0, v1, 42.42
v_med3_f32 v0, s0, s0, s1
// GFX10: v_med3_f32 v0, s0, s0, s1 ; encoding: [0x00,0x00,0x57,0xd5,0x00,0x00,0x04,0x00]

//-----------------------------------------------------------------------------------------
// 64-bit shift instructions can use only one scalar value input

v_ashrrev_i64 v[0:1], 0x100, s[0:1]
// GFX10-ERR: error: invalid operand (violates constant bus restrictions)

v_ashrrev_i64 v[0:1], s2, s[0:1]
// GFX10-ERR: error: invalid operand (violates constant bus restrictions)

//-----------------------------------------------------------------------------------------
// v_div_fmas implicitly reads VCC, so only one scalar operand is possible

Expand All @@ -38,6 +47,9 @@ v_div_fmas_f64 v[5:6], v[1:2], s[2:3], 0x123456
// v_mad_u64_u32 has operands of different sizes.
// When these operands are literals, they are counted as 2 scalar values even if literals are identical.

v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273
// GFX10-ERR: error: invalid operand (violates constant bus restrictions)

v_mad_u64_u32 v[5:6], s12, v1, 0x12345678, 0x12345678
// GFX10: v_mad_u64_u32 v[5:6], s12, v1, 0x12345678, 0x12345678 ; encoding: [0x05,0x0c,0x76,0xd5,0x01,0xff,0xfd,0x03,0x78,0x56,0x34,0x12]

Expand Down
4 changes: 0 additions & 4 deletions llvm/test/MC/AMDGPU/vop3-literal.s
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ v_lshlrev_b64 v[5:6], v1, 0x3f717273
// GFX10: v_lshlrev_b64 v[5:6], v1, 0x3f717273 ; encoding: [0x05,0x00,0xff,0xd6,0x01,0xff,0x01,0x00,0x73,0x72,0x71,0x3f]
// GFX9-ERR: error: invalid literal operand

v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273
// GFX10: v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273 ; encoding: [0x05,0x00,0xff,0xd6,0xff,0xfe,0x01,0x00,0x73,0x72,0x71,0x3f]
// GFX9-ERR: error: invalid literal operand

v_fma_mix_f32 v5, 0x123, v2, v3
// GFX10: v_fma_mix_f32 v5, 0x123, v2, v3 ; encoding: [0x05,0x00,0x20,0xcc,0xff,0x04,0x0e,0x04,0x23,0x01,0x00,0x00]

Expand Down

0 comments on commit fe2ee4c

Please sign in to comment.