Skip to content

Commit b0e07ee

Browse files
committed
[AMDGPU] Verify SdwaSel value range
Ensure that the MachineVerifier verifies that the value provided for an SDWA selection is a valid value for the SdwaSel enum.
1 parent eeb8c20 commit b0e07ee

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4916,6 +4916,18 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
49164916
return false;
49174917
}
49184918

4919+
for (auto Op : {AMDGPU::OpName::src0_sel, AMDGPU::OpName::src1_sel,
4920+
AMDGPU::OpName::dst_sel}) {
4921+
const MachineOperand *MO = getNamedOperand(MI, Op);
4922+
if (!MO)
4923+
continue;
4924+
int64_t Imm = MO->getImm();
4925+
if (Imm < 0 || Imm > AMDGPU::SDWA::SdwaSel::DWORD) {
4926+
ErrInfo = "Invalid SDWA selection";
4927+
return false;
4928+
}
4929+
}
4930+
49194931
int DstIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::vdst);
49204932

49214933
for (int OpIdx : {DstIdx, Src0Idx, Src1Idx, Src2Idx}) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: not --crash llc -mtriple=amdgcn -mcpu=gfx1030 --verify-machineinstrs -o - %s 2>&1 | FileCheck %s
2+
3+
# CHECK-COUNT-6: *** Bad machine code: Invalid SDWA selection ***
4+
# CHECK-NOT: *** Bad machine code
5+
# CHECK: LLVM ERROR: Found 6 machine code errors
6+
7+
---
8+
name: invalid_sdwa_selection
9+
tracksRegLiveness: true
10+
body: |
11+
bb.0:
12+
liveins: $vgpr0
13+
%0:vgpr_32 = COPY $vgpr0
14+
%1:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 1, 0, 7, 0, implicit $exec
15+
%2:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 1, 0, -1, 0, implicit $exec
16+
%3:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 7, 0, 6, 0, implicit $exec
17+
%4:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, -1, 0, 6, 0, implicit $exec
18+
%5:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 0, 0, 0, 7, implicit $exec
19+
%6:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 0, 0, 0, -1, implicit $exec
20+
21+
S_ENDPGM 0
22+
...

0 commit comments

Comments
 (0)