Skip to content

[AMDGPU] Put back ProperlyAlignedRC helper functions - #175000

Closed
cdevadas wants to merge 9 commits into
mainfrom
users/cdevadas/putback-ProperlyAlighedRC
Closed

cdevadas wants to merge 9 commits into
mainfrom
users/cdevadas/putback-ProperlyAlighedRC

Conversation

@cdevadas

@cdevadas cdevadas commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Putting back the functions that are recently deleted
as they were found unused. They are needed for
implementing subreg reload during RA.

cdevadas commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@llvmbot

llvmbot commented Jan 8, 2026 •

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-llvm-regalloc

@llvm/pr-subscribers-backend-amdgpu

Author: Christudasan Devadasan (cdevadas)

Changes

Putting back the functions that are recently deleted
as they were found unused. They are needed for
implementing subreg reload during RA.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp (+22)
  • (modified) llvm/lib/Target/AMDGPU/SIRegisterInfo.h (+5)
diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
index c45f5ccc10ccd..f21ad7b59cb23 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
@@ -4030,6 +4030,28 @@ bool SIRegisterInfo::isProperlyAlignedRC(const TargetRegisterClass &RC) const {
   return true;
 }
 
+const TargetRegisterClass *
+SIRegisterInfo::getProperlyAlignedRC(const TargetRegisterClass *RC) const {
+  if (!RC || !ST.needsAlignedVGPRs())
+    return RC;
+
+  unsigned Size = getRegSizeInBits(*RC);
+  if (Size <= 32)
+    return RC;
+
+  if (RC == &AMDGPU::VS_64RegClass)
+    return &AMDGPU::VS_64_Align2RegClass;
+
+  if (isVGPRClass(RC))
+    return getAlignedVGPRClassForBitWidth(Size);
+  if (isAGPRClass(RC))
+    return getAlignedAGPRClassForBitWidth(Size);
+  if (isVectorSuperClass(RC))
+    return getAlignedVectorSuperClassForBitWidth(Size);
+
+  return RC;
+}
+
 ArrayRef<MCPhysReg>
 SIRegisterInfo::getAllSGPR128(const MachineFunction &MF) const {
   return ArrayRef(AMDGPU::SGPR_128RegClass.begin(), ST.getMaxNumSGPRs(MF) / 4);
diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
index b959fe7cf2db1..1b12eea6dfcc3 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
@@ -433,6 +433,11 @@ class SIRegisterInfo final : public AMDGPUGenRegisterInfo {
   // the subtarget.
   bool isProperlyAlignedRC(const TargetRegisterClass &RC) const;
 
+  // Given \p RC returns corresponding aligned register class if required
+  // by the subtarget.
+  const TargetRegisterClass *
+  getProperlyAlignedRC(const TargetRegisterClass *RC) const;
+
   /// Return all SGPR128 which satisfy the waves per execution unit requirement
   /// of the subtarget.
   ArrayRef<MCPhysReg> getAllSGPR128(const MachineFunction &MF) const;

@jayfoad jayfoad changed the title [AMDGPU] Put back ProperlyAlighedRC helper functions [AMDGPU] Put back ProperlyAlignedRC helper functions Jan 8, 2026

@arsenm arsenm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be reintroduced. Instruction constraints should be taken directly from the relevant use instructions, this is unnecessary hardcoding. Spills should not have hard alignment restrictions

@cdevadas

Copy link
Copy Markdown
Contributor Author

This should not be reintroduced. Instruction constraints should be taken directly from the relevant use instructions, this is unnecessary hardcoding. Spills should not have hard alignment restrictions

Can you elaborate on it? How, during RA, can the newly introduced regclasses be constrained for their uses? Currently, there is an MIR verifier error for the spill and its subsequent uses for not meeting the alignment requirements.

@cdevadas
cdevadas force-pushed the users/cdevadas/enhance-createFrom-function branch from b86e3c5 to 975be2f Compare January 12, 2026 13:29
@cdevadas
cdevadas force-pushed the users/cdevadas/putback-ProperlyAlighedRC branch from 64d13e3 to 5647ba0 Compare January 12, 2026 13:29
@cdevadas
cdevadas force-pushed the users/cdevadas/enhance-createFrom-function branch from 975be2f to acb9b34 Compare January 12, 2026 15:29
@cdevadas
cdevadas force-pushed the users/cdevadas/putback-ProperlyAlighedRC branch from 5647ba0 to 1a83444 Compare January 12, 2026 15:29
Currently, SGPR spill pseudo-instructions lack
an offset field to represent non-zero stack offsets.
This patch introduces an additional offset field to
SGPR spill pseudo-instructions and updates all
relevant passes that handle spill lowering to support
this new field. This field is essential for a future
patch that implements subreg reload of tuple registers
from their stack location during RA.
AMDGPURewriteAGPRCopyMFMA pass is currently not subreg-aware.
In particular, the logic that optimizes spills into COPY
instructions assumes full register reloads. This becomes
problematic when the reload instruction partially restores
a tuple register. This patch introduces the necessary changes
to make this pass subreg-aware, for a future patch that
implements subreg reload during RA.
Instead of just cloning the virtual register, this
function now creates a new virtual register derived
from a subregister class of the original value.
Putting back the functions that are recently deleted
as they were found unused. They are needed for
implementing subreg reload during RA.
@cdevadas
cdevadas force-pushed the users/cdevadas/enhance-createFrom-function branch from acb9b34 to 4343cad Compare January 13, 2026 05:07
@cdevadas
cdevadas force-pushed the users/cdevadas/putback-ProperlyAlighedRC branch from 1a83444 to c74c50e Compare January 13, 2026 05:07
@arsenm

arsenm commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Can you elaborate on it? How, during RA, can the newly introduced regclasses be constrained for their uses?

This shouldn't be necessary. The spill pseudos should support any register class, always. They can be split up as required to satisfy alignment when the pseudo is expanded

@cdevadas

Copy link
Copy Markdown
Contributor Author

Can you elaborate on it? How, during RA, can the newly introduced regclasses be constrained for their uses?

This shouldn't be necessary. The spill pseudos should support any register class, always. They can be split up as required to satisfy alignment when the pseudo is expanded

Yep. #177317 is meant to fix the align constraints for spill pseudos. I will cloes this PR when @easyonaadit lands this spill pseudo fixup patch after approval.

@easyonaadit
easyonaadit deleted the users/cdevadas/putback-ProperlyAlighedRC branch July 31, 2026 09:23
@easyonaadit
easyonaadit restored the users/cdevadas/putback-ProperlyAlighedRC branch July 31, 2026 09:31
@easyonaadit easyonaadit reopened this Jul 31, 2026
@easyonaadit
easyonaadit changed the base branch from users/cdevadas/enhance-createFrom-function to main July 31, 2026 09:32
@easyonaadit
easyonaadit deleted the users/cdevadas/putback-ProperlyAlighedRC branch July 31, 2026 09:33
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