Skip to content

Commit 70306f7

Browse files
committed
[AMDGPU][AsmParser] Allow v_writelane_b32 to use SGPR and M0 as source operands at the same time
Currently the asm parser takes `v_writelane_b32 v1, s13, m0` as illegal instruction for pre-gfx11 because it uses two constant buses while the hardware can only allow one. However, based on the comment of `AMDGPUInstructionSelector::selectWritelane`, it is allowed to have M0 as lane selector and a SGPR used as SRC0 because the lane selector doesn't count as a use of constant bus. In fact, codegen can already generate this form, but this inconsistency is not exposed because the validation of constant bus limitation only happens when paring an assembly but we don't have a test case when both SGPR and M0 used as source operands for the instruction.
1 parent ddad7e3 commit 70306f7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,34 @@ bool AMDGPUAsmParser::validateConstantBusLimitations(
35243524
!isVOPD(Opcode))
35253525
return true;
35263526

3527+
// Based on the comment for `AMDGPUInstructionSelector::selectWritelane`:
3528+
// Writelane is special in that it can use SGPR and M0 (which would normally
3529+
// count as using the constant bus twice - but in this case it is allowed
3530+
// since the lane selector doesn't count as a use of the constant bus).
3531+
// However, it is still required to abide by the 1 SGPR rule.
3532+
switch (Opcode) {
3533+
default:
3534+
break;
3535+
case V_WRITELANE_B32_e64_gfx11:
3536+
case V_WRITELANE_B32_e64_gfx12:
3537+
case V_WRITELANE_B32_gfx10:
3538+
case V_WRITELANE_B32_gfx6_gfx7:
3539+
case V_WRITELANE_B32_vi: {
3540+
const MCOperand &LaneSelOp = Inst.getOperand(2);
3541+
if (LaneSelOp.isReg()) {
3542+
auto LaneSelReg = mc2PseudoReg(LaneSelOp.getReg());
3543+
switch (LaneSelReg) {
3544+
default:
3545+
break;
3546+
case M0:
3547+
case M0_gfxpre11:
3548+
case M0_gfx11plus:
3549+
return true;
3550+
}
3551+
}
3552+
}
3553+
}
3554+
35273555
// Check special imm operands (used by madmk, etc)
35283556
if (AMDGPU::hasNamedOperand(Opcode, AMDGPU::OpName::imm)) {
35293557
++NumLiterals;

llvm/test/MC/AMDGPU/writelane_m0.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: llvm-mc --triple=amdgcn --mcpu=gfx904 %s | FileCheck %s
2+
// RUN: llvm-mc --triple=amdgcn --mcpu=gfx940 %s | FileCheck %s
3+
// RUN: llvm-mc --triple=amdgcn --mcpu=gfx1010 %s | FileCheck %s
4+
// RUN: llvm-mc --triple=amdgcn --mcpu=gfx1030 %s | FileCheck %s
5+
// RUN: llvm-mc --triple=amdgcn --mcpu=gfx1100 %s | FileCheck %s
6+
7+
.text
8+
v_writelane_b32 v1, s13, m0
9+
10+
// CHECK: v_writelane_b32 v1, s13, m0

0 commit comments

Comments
 (0)