Skip to content

AMDGPU: Directly check if shrink-instructions run is post-RA #142009

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 1 commit into from
May 30, 2025

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 29, 2025

No description provided.

Copy link
Contributor Author

arsenm commented May 29, 2025

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

@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/frexp-constant-fold.ll (+1-1)
diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
index 412f0432e85cc..0eb55daf32089 100644
--- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
+++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
@@ -33,6 +33,7 @@ class SIShrinkInstructions {
   const GCNSubtarget *ST;
   const SIInstrInfo *TII;
   const SIRegisterInfo *TRI;
+  bool IsPostRA;
 
   bool foldImmediates(MachineInstr &MI, bool TryToCommute = true) const;
   bool shouldShrinkTrue16(MachineInstr &MI) const;
@@ -417,7 +418,7 @@ void SIShrinkInstructions::shrinkMadFma(MachineInstr &MI) const {
     return;
 
   // There is no advantage to doing this pre-RA.
-  if (!MF->getProperties().hasNoVRegs())
+  if (!IsPostRA)
     return;
 
   if (TII->hasAnyModifiersSet(MI))
@@ -837,6 +838,7 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
   ST = &MF.getSubtarget<GCNSubtarget>();
   TII = ST->getInstrInfo();
   TRI = &TII->getRegisterInfo();
+  IsPostRA = MF.getProperties().hasNoVRegs();
 
   unsigned VCCReg = ST->isWave32() ? AMDGPU::VCC_LO : AMDGPU::VCC;
 
@@ -857,9 +859,8 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
 
         // Test if we are after regalloc. We only want to do this after any
         // optimizations happen because this will confuse them.
-        // XXX - not exactly a check for post-regalloc run.
         MachineOperand &Src = MI.getOperand(1);
-        if (Src.isImm() && MI.getOperand(0).getReg().isPhysical()) {
+        if (Src.isImm() && IsPostRA) {
           int32_t ModImm;
           unsigned ModOpcode =
               canModifyToInlineImmOp32(TII, Src, ModImm, /*Scalar=*/false);
@@ -948,9 +949,8 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
           continue;
       }
 
-      if (TII->isMIMG(MI.getOpcode()) &&
-          ST->getGeneration() >= AMDGPUSubtarget::GFX10 &&
-          MF.getProperties().hasNoVRegs()) {
+      if (IsPostRA && TII->isMIMG(MI.getOpcode()) &&
+          ST->getGeneration() >= AMDGPUSubtarget::GFX10) {
         shrinkMIMG(MI);
         continue;
       }
@@ -1061,7 +1061,7 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
       // fold an immediate into the shrunk instruction as a literal operand. In
       // GFX10 VOP3 instructions can take a literal operand anyway, so there is
       // no advantage to doing this.
-      if (ST->hasVOP3Literal() && !MF.getProperties().hasNoVRegs())
+      if (ST->hasVOP3Literal() && !IsPostRA)
         continue;
 
       if (ST->hasTrue16BitInsts() && AMDGPU::isTrue16Inst(MI.getOpcode()) &&
diff --git a/llvm/test/CodeGen/AMDGPU/frexp-constant-fold.ll b/llvm/test/CodeGen/AMDGPU/frexp-constant-fold.ll
index 2e75b90c00968..ce44c372ac3a7 100644
--- a/llvm/test/CodeGen/AMDGPU/frexp-constant-fold.ll
+++ b/llvm/test/CodeGen/AMDGPU/frexp-constant-fold.ll
@@ -108,8 +108,8 @@ define { <2 x float>, <2 x i32> } @frexp_zero_negzero_vector() {
 ; CHECK-LABEL: frexp_zero_negzero_vector:
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; CHECK-NEXT:    v_bfrev_b32_e32 v1, 1
 ; CHECK-NEXT:    v_mov_b32_e32 v0, 0
+; CHECK-NEXT:    v_bfrev_b32_e32 v1, 1
 ; CHECK-NEXT:    v_mov_b32_e32 v2, 0
 ; CHECK-NEXT:    v_mov_b32_e32 v3, 0
 ; CHECK-NEXT:    s_setpc_b64 s[30:31]

@arsenm arsenm marked this pull request as ready for review May 29, 2025 18:37
Copy link
Contributor

@broxigarchen broxigarchen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor Author

arsenm commented May 30, 2025

Merge activity

  • May 30, 1:50 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 30, 1:52 PM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm merged commit f70e920 into main May 30, 2025
15 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu-use-real-is-post-ra-shrink-check branch May 30, 2025 13:52
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
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