-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
arsenm
merged 1 commit into
main
from
users/arsenm/amdgpu-use-real-is-post-ra-shrink-check
May 30, 2025
Merged
AMDGPU: Directly check if shrink-instructions run is post-RA #142009
arsenm
merged 1 commit into
main
from
users/arsenm/amdgpu-use-real-is-post-ra-shrink-check
May 30, 2025
Conversation
This file contains hidden or 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
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/142009.diff 2 Files Affected:
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]
|
rampitec
approved these changes
May 29, 2025
broxigarchen
approved these changes
May 29, 2025
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
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
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.
No description provided.