-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU] Verify SdwaSel value range #128898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ensure that the MachineVerifier verifies that the value provided for an SDWA selection is a valid value for the SdwaSel enum.
@llvm/pr-subscribers-backend-amdgpu Author: Frederik Harwath (frederik-h) ChangesEnsure that the MachineVerifier verifies that the value provided for an SDWA selection is a valid value for the SdwaSel enum. Full diff: https://github.com/llvm/llvm-project/pull/128898.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 2ef628a7c569c..ceadc81aa56ac 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -4916,6 +4916,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/CodeGen/AMDGPU/verifier-sdwa-selection.mir b/llvm/test/CodeGen/AMDGPU/verifier-sdwa-selection.mir
new file mode 100644
index 0000000000000..8517b0ad53458
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/verifier-sdwa-selection.mir
@@ -0,0 +1,22 @@
+# RUN: not --crash llc -mtriple=amdgcn -mcpu=gfx1030 --verify-machineinstrs -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
+...
|
arsenm
reviewed
Feb 26, 2025
arsenm
approved these changes
Feb 26, 2025
@arsenm Thanks for the review! |
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Mar 3, 2025
Make the MachineVerifier check that the value provided for an SDWA selection is a valid value for the SdwaSel enum.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ensure that the MachineVerifier verifies that the value provided for an SDWA selection is a valid value for the SdwaSel enum.