[llvm] 50b508c - [AMDGPU] Verify SdwaSel value range (#128898)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 23:11:32 PST 2025
Author: Frederik Harwath
Date: 2025-02-27T08:11:29+01:00
New Revision: 50b508cc7b2d95f92896df73f49063b5aafec43d
URL: https://github.com/llvm/llvm-project/commit/50b508cc7b2d95f92896df73f49063b5aafec43d
DIFF: https://github.com/llvm/llvm-project/commit/50b508cc7b2d95f92896df73f49063b5aafec43d.diff
LOG: [AMDGPU] Verify SdwaSel value range (#128898)
Make the MachineVerifier check that the value provided for an SDWA selection is a
valid value for the SdwaSel enum.
Added:
llvm/test/MachineVerifier/AMDGPU/verifier-sdwa-selection.mir
Modified:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index db49b7893821a..9aec2bef0c18a 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -4920,6 +4920,18 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
return false;
}
+ for (auto Op : {AMDGPU::OpName::src0_sel, AMDGPU::OpName::src1_sel,
+ AMDGPU::OpName::dst_sel}) {
+ const MachineOperand *MO = getNamedOperand(MI, Op);
+ if (!MO)
+ continue;
+ int64_t Imm = MO->getImm();
+ if (Imm < 0 || Imm > AMDGPU::SDWA::SdwaSel::DWORD) {
+ ErrInfo = "Invalid SDWA selection";
+ return false;
+ }
+ }
+
int DstIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::vdst);
for (int OpIdx : {DstIdx, Src0Idx, Src1Idx, Src2Idx}) {
diff --git a/llvm/test/MachineVerifier/AMDGPU/verifier-sdwa-selection.mir b/llvm/test/MachineVerifier/AMDGPU/verifier-sdwa-selection.mir
new file mode 100644
index 0000000000000..5387ea8eb1dd8
--- /dev/null
+++ b/llvm/test/MachineVerifier/AMDGPU/verifier-sdwa-selection.mir
@@ -0,0 +1,22 @@
+# RUN: not --crash llc -mtriple=amdgcn -mcpu=gfx1030 -run-pass=none -o - %s 2>&1 | FileCheck %s
+
+# CHECK-COUNT-6: *** Bad machine code: Invalid SDWA selection ***
+# CHECK-NOT: *** Bad machine code
+# CHECK: LLVM ERROR: Found 6 machine code errors
+
+---
+name: invalid_sdwa_selection
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0
+ %0:vgpr_32 = COPY $vgpr0
+ %1:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 1, 0, 7, 0, implicit $exec
+ %2:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 1, 0, -1, 0, implicit $exec
+ %3:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 7, 0, 6, 0, implicit $exec
+ %4:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, -1, 0, 6, 0, implicit $exec
+ %5:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 0, 0, 0, 7, implicit $exec
+ %6:vgpr_32 = V_LSHRREV_B32_sdwa 0, %0:vgpr_32, 0, %0:vgpr_32, 0, 0, 0, 0, -1, implicit $exec
+
+ S_ENDPGM 0
+...
More information about the llvm-commits
mailing list