-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
AMDGPU: Fix verifier assert with out of bounds subregister indexes #119799
Merged
arsenm
merged 1 commit into
main
from
users/arsenm/amdgpu-verifier-fix-assert-oob-subreg-index-aligned-vgpr
Dec 13, 2024
Merged
AMDGPU: Fix verifier assert with out of bounds subregister indexes #119799
arsenm
merged 1 commit into
main
from
users/arsenm/amdgpu-verifier-fix-assert-oob-subreg-index-aligned-vgpr
Dec 13, 2024
Conversation
This file contains 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
The manual check for aligned VGPR classes would assert if a virtual register used an index not supported by the register class.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesThe manual check for aligned VGPR classes would assert if a virtual Full diff: https://github.com/llvm/llvm-project/pull/119799.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 4a94d690297949..057412d41e7a2f 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -4771,11 +4771,12 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
if (ST.needsAlignedVGPRs()) {
const TargetRegisterClass *RC = RI.getRegClassForReg(MRI, Reg);
if (RI.hasVectorRegisters(RC) && MO.getSubReg()) {
- const TargetRegisterClass *SubRC =
- RI.getSubRegisterClass(RC, MO.getSubReg());
- RC = RI.getCompatibleSubRegClass(RC, SubRC, MO.getSubReg());
- if (RC)
- RC = SubRC;
+ if (const TargetRegisterClass *SubRC =
+ RI.getSubRegisterClass(RC, MO.getSubReg())) {
+ RC = RI.getCompatibleSubRegClass(RC, SubRC, MO.getSubReg());
+ if (RC)
+ RC = SubRC;
+ }
}
// Check that this is the aligned version of the class.
diff --git a/llvm/test/MachineVerifier/AMDGPU/unsupported-subreg-index-aligned-vgpr-check.mir b/llvm/test/MachineVerifier/AMDGPU/unsupported-subreg-index-aligned-vgpr-check.mir
new file mode 100644
index 00000000000000..651a9d71ae3209
--- /dev/null
+++ b/llvm/test/MachineVerifier/AMDGPU/unsupported-subreg-index-aligned-vgpr-check.mir
@@ -0,0 +1,41 @@
+# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -run-pass=none -filetype=null %s 2>&1 | FileCheck %s
+
+# sub16_sub17_sub18_sub19 is outside the bounds of a 512-bit
+# register. Make sure the verification doesn't assert. This was only
+# broken for targets that require even aligned VGPRs due to the manual
+# alignment check.
+
+---
+name: uses_invalid_subregister_for_regclass
+tracksRegLiveness: true
+body: |
+ bb.0:
+ %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+ S_NOP 0, implicit-def %1:vreg_512_align2
+
+
+ ; CHECK: *** Bad machine code: Invalid subregister index for virtual register ***
+ ; CHECK-NEXT: - function: uses_invalid_subregister_for_regclass
+ ; CHECK-NEXT: - basic block: %bb.0
+ ; CHECK-NEXT: - instruction: GLOBAL_STORE_DWORDX4_SADDR %0:vgpr_32, %1.sub16_sub17_sub18_sub19:vreg_512_align2, undef $sgpr8_sgpr9, 80, 0, implicit $exec :: (store (s128), addrspace 1)
+ ; CHECK-NEXT: - operand 1: %1.sub16_sub17_sub18_sub19:vreg_512_align2
+ ; CHECK-NEXT: Register class VReg_512_Align2 does not support subreg index 166
+
+ ; CHECK: *** Bad machine code: Subtarget requires even aligned vector registers ***
+ ; CHECK-NEXT: - function: uses_invalid_subregister_for_regclass
+ ; CHECK-NEXT: - basic block: %bb.0
+ ; CHECK-NEXT: - instruction: GLOBAL_STORE_DWORDX4_SADDR %0:vgpr_32, %2.sub16_sub17_sub18_sub19:vreg_512, undef $sgpr8_sgpr9, 80, 0, implicit $exec :: (store (s128), addrspace 1)
+ GLOBAL_STORE_DWORDX4_SADDR %0, %1.sub16_sub17_sub18_sub19, undef $sgpr8_sgpr9, 80, 0, implicit $exec :: (store (s128), addrspace 1)
+
+ ; Test with unaligned class
+ ; CHECK: *** Bad machine code: Invalid subregister index for virtual register ***
+ ; CHECK-NEXT: - function: uses_invalid_subregister_for_regclass
+ ; CHECK-NEXT: - basic block: %bb.0
+ ; CHECK-NEXT: - instruction: GLOBAL_STORE_DWORDX4_SADDR %0:vgpr_32, %2.sub16_sub17_sub18_sub19:vreg_512, undef $sgpr8_sgpr9, 80, 0, implicit $exec :: (store (s128), addrspace 1)
+ ; CHECK-NEXT: - operand 1: %2.sub16_sub17_sub18_sub19:vreg_512
+ ; CHECK-NEXT: Register class VReg_512 does not support subreg index 166
+ S_NOP 0, implicit-def %2:vreg_512
+ GLOBAL_STORE_DWORDX4_SADDR %0, %2.sub16_sub17_sub18_sub19, undef $sgpr8_sgpr9, 80, 0, implicit $exec :: (store (s128), addrspace 1)
+ S_ENDPGM 0
+
+...
|
cdevadas
approved these changes
Dec 13, 2024
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.
The manual check for aligned VGPR classes would assert if a virtual
register used an index not supported by the register class.