Skip to content

Commit fc149a7

Browse files
frederik-hjoaosaffran
authored andcommitted
[AMDGPU] Verify SdwaSel value range (llvm#128898)
Make the MachineVerifier check that the value provided for an SDWA selection is a valid value for the SdwaSel enum.
1 parent c5cbfe2 commit fc149a7

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
@@ -4920,6 +4920,18 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
49204920
return false;
49214921
}
49224922

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

49254937
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 -run-pass=none -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)