Skip to content

AMDGPU: Fix assert on physreg MUBUF rsrc operand #120815

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

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Dec 21, 2024

The stack case uses a physical register and should not ordinarily
reach here, but strange things happen at -O0. The testcase still
errors because we do not yet attempt to handle arbitrary dynamic
sized allocas yet.

Fixes: SWDEV-503538

The stack case uses a physical register and should not ordinarily
reach here, but strange things happen at -O0. The testcase still
errors because we do not yet attempt to handle arbitrary dynamic
sized allocas yet.

Fixes: SWDEV-503538
Copy link
Contributor Author

arsenm commented Dec 21, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review December 21, 2024 02:09
@llvmbot
Copy link
Member

llvmbot commented Dec 21, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

The stack case uses a physical register and should not ordinarily
reach here, but strange things happen at -O0. The testcase still
errors because we do not yet attempt to handle arbitrary dynamic
sized allocas yet.

Fixes: SWDEV-503538


Full diff: https://github.com/llvm/llvm-project/pull/120815.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.cpp (+1-2)
  • (added) llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll (+23)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index f97ea40caa6704..7e61aa9cd1da6a 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -6866,9 +6866,8 @@ SIInstrInfo::legalizeOperands(MachineInstr &MI,
       AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::srsrc);
   if (RsrcIdx != -1) {
     MachineOperand *Rsrc = &MI.getOperand(RsrcIdx);
-    if (Rsrc->isReg() && !RI.isSGPRClass(MRI.getRegClass(Rsrc->getReg()))) {
+    if (Rsrc->isReg() && !RI.isSGPRReg(MRI, Rsrc->getReg()))
       isRsrcLegal = false;
-    }
   }
 
   // The operands are legal.
diff --git a/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll b/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll
new file mode 100644
index 00000000000000..6849c8b4e609ee
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll
@@ -0,0 +1,23 @@
+; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 2> %t.err < %s | FileCheck %s
+; RUN: FileCheck -check-prefix=ERR %s < %t.err
+
+; FIXME: This error will be fixed by supporting arbitrary divergent
+; dynamic allocas by performing a wave umax of the size.
+
+; ERR: error: <unknown>:0:0: in function move_to_valu_assert_srd_is_physreg_swdev503538 i32 (ptr addrspace(1)): illegal VGPR to SGPR copy
+
+; CHECK: ; illegal copy v0 to s32
+
+define i32 @move_to_valu_assert_srd_is_physreg_swdev503538(ptr addrspace(1) %ptr) {
+entry:
+  %idx = load i32, ptr addrspace(1) %ptr, align 4
+  %zero = extractelement <4 x i32> zeroinitializer, i32 %idx
+  %alloca = alloca [2048 x i8], i32 %zero, align 8, addrspace(5)
+  %ld = load i32, ptr addrspace(5) %alloca, align 8
+  call void @llvm.memset.p5.i32(ptr addrspace(5) %alloca, i8 0, i32 2048, i1 false)
+  ret i32 %ld
+}
+
+declare void @llvm.memset.p5.i32(ptr addrspace(5) nocapture writeonly, i8, i32, i1 immarg) #0
+
+attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }

@arsenm arsenm merged commit f6365a4 into main Jan 7, 2025
12 checks passed
@arsenm arsenm deleted the users/arsenm/swdev503538/fix-assert-on-mubuf-physreg-srd branch January 7, 2025 01:11
@mikaelholmen
Copy link
Collaborator

Not sure what happens but I see that
llvm/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll
fails if I run it when I've compiled with EXPENSIVE_CHECKS

-> build-all-expensive/bin/llvm-lit -av test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll                                                                                  -- Testing: 1 tests, 1 workers --
FAIL: LLVM :: CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll (1 of 1)
******************** TEST 'LLVM :: CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
RUN: at line 1: not /repo/llvm/build-all-expensive/bin/llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 2> /repo/llvm/build-all-expensive/test/CodeGen/AMDGPU/Output/swdev503538-move-to-valu-stack-srd-physreg.ll.tmp.err < /repo/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll | /repo/llvm/build-all-expensive/bin/FileCheck /repo/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll
+ /repo/llvm/build-all-expensive/bin/FileCheck /repo/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll
+ not /repo/llvm/build-all-expensive/bin/llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /repo/llvm/build-all-expensive/bin/FileCheck /repo/llvm/test/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll

--

********************
********************
Failed Tests (1):
  LLVM :: CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll

@arsenm
Copy link
Contributor Author

arsenm commented Jan 7, 2025

Not sure what happens but I see that llvm/CodeGen/AMDGPU/swdev503538-move-to-valu-stack-srd-physreg.ll fails if I run it when I've compiled with EXPENSIVE_CHECKS

This test needs to explicitly disable the verifier since it's broken

@arsenm
Copy link
Contributor Author

arsenm commented Jan 7, 2025

This test needs to explicitly disable the verifier since it's broken

Done in 7899572

@mikaelholmen
Copy link
Collaborator

This test needs to explicitly disable the verifier since it's broken

Done in 7899572

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants