-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[AMDGPU] Fix AGPR_32 reg assign for mfma scale ops #168964
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
Conversation
In MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format.
|
@llvm/pr-subscribers-backend-amdgpu Author: None (hjagasiaAMD) ChangesIn MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format. Full diff: https://github.com/llvm/llvm-project/pull/168964.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
index 89c16dadb4b41..b5e3187289160 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
@@ -302,6 +302,10 @@ bool AMDGPURewriteAGPRCopyMFMAImpl::attemptReassignmentsToAGPR(
const TargetRegisterClass *EquivalentAGPRRegClass =
TRI.getEquivalentAGPRClass(MRI.getRegClass(InterferingReg));
+ // Do not reassign scale operands
+ if (EquivalentAGPRRegClass == &AMDGPU::AGPR_32RegClass)
+ return false;
+
MCPhysReg Assignable = AMDGPU::NoRegister;
if (EquivalentAGPRRegClass->contains(PrefPhysReg) &&
LRM.checkInterference(ReassignLI, PrefPhysReg) ==
diff --git a/llvm/test/CodeGen/AMDGPU/rewrite-vgpr-mfma-scale-to-agpr.mir b/llvm/test/CodeGen/AMDGPU/rewrite-vgpr-mfma-scale-to-agpr.mir
index ab56c9982753f..12be806960b67 100644
--- a/llvm/test/CodeGen/AMDGPU/rewrite-vgpr-mfma-scale-to-agpr.mir
+++ b/llvm/test/CodeGen/AMDGPU/rewrite-vgpr-mfma-scale-to-agpr.mir
@@ -1,6 +1,6 @@
-# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -run-pass=greedy,amdgpu-rewrite-agpr-copy-mfma -verify-machineinstrs -o - %s 2>&1 | FileCheck %s
-# CHECK: Illegal virtual register for instruction
-# CHECK: Expected a VGPR_32 register, but got a AGPR_32 register
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -run-pass=greedy,amdgpu-rewrite-agpr-copy-mfma -verify-machineinstrs -o - %s 2>&1 | FileCheck %s
+# CHECK-NOT: Illegal virtual register for instruction
+# CHECK-NOT: Expected a VGPR_32 register, but got a AGPR_32 register
# Test for issue in amdgpu-rewrite-agpr-copy-mfma, which reassigns scale operand
# in vgpr_32 register to agpr_32, not permitted by instruction format.
|
| # CHECK: Illegal virtual register for instruction | ||
| # CHECK: Expected a VGPR_32 register, but got a AGPR_32 register | ||
| # RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -run-pass=greedy,amdgpu-rewrite-agpr-copy-mfma -verify-machineinstrs -o - %s 2>&1 | FileCheck %s | ||
| # CHECK-NOT: Illegal virtual register for instruction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-NOT checks are close to useless, especially for checking error messages. Generate checks for the actual output
| TRI.getEquivalentAGPRClass(MRI.getRegClass(InterferingReg)); | ||
|
|
||
| // Do not reassign scale operands | ||
| if (EquivalentAGPRRegClass == &AMDGPU::AGPR_32RegClass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like the right condition. It just happens the scale operands are the only 32-bit input case. This should more directly check the operand constraint instead of checking a hardcodes class equality
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
ronlieb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, need @arsenm to do final approve
| if (isRewriteCandidate(*MI)) { | ||
|
|
||
| int AGPROp = AMDGPU::getMFMASrcCVDstAGPROp(MI->getOpcode()); | ||
| MachineInstrBuilder TmpMIB = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely should not be creating temporary instructions
| unsigned OpNo = &MO - &MI->getOperand(0); | ||
| const TargetRegisterClass *EquivalentAGPRRegClass = | ||
| TRI.getEquivalentAGPRClass(MRI.getRegClass(Reg)); | ||
| const TargetRegisterClass *Allowed = TmpMI->getRegClassConstraintEffect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want TargetInstrInfo::getRegClass to get the static constraint of the known operand (alternatively, you could check that the use is one of the known src0/src1 operands and not the _scale name)
Co-authored-by: Matt Arsenault <[email protected]>
Co-authored-by: Matt Arsenault <[email protected]>
Co-authored-by: Matt Arsenault <[email protected]>
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
In MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format. --------- Co-authored-by: Matt Arsenault <[email protected]>
In MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format. --------- Co-authored-by: Matt Arsenault <[email protected]>
In MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format.