Skip to content

AMDGPU: Delete seemingly dead s_fmaak_f32/s_fmamk_f32 folding code #140580

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 May 19, 2025

No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.

@arsenm arsenm marked this pull request as ready for review May 19, 2025 17:22
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.


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

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIFoldOperands.cpp (-11)
diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
index 92937e33fd500..d94c2d8b03dff 100644
--- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -767,17 +767,6 @@ bool SIFoldOperandsImpl::tryAddToFoldList(
     return true;
   }
 
-  // Inlineable constant might have been folded into Imm operand of fmaak or
-  // fmamk and we are trying to fold a non-inlinable constant.
-  if ((Opc == AMDGPU::S_FMAAK_F32 || Opc == AMDGPU::S_FMAMK_F32) &&
-      !OpToFold->isReg() && !TII->isInlineConstant(*OpToFold)) {
-    unsigned ImmIdx = Opc == AMDGPU::S_FMAAK_F32 ? 3 : 2;
-    MachineOperand &OpImm = MI->getOperand(ImmIdx);
-    if (!OpImm.isReg() &&
-        TII->isInlineConstant(*MI, MI->getOperand(OpNo), OpImm))
-      return tryToFoldAsFMAAKorMK();
-  }
-
   // Special case for s_fmac_f32 if we are trying to fold into Src0 or Src1.
   // By changing into fmamk we can untie Src2.
   // If folding for Src0 happens first and it is identical operand to Src1 we

Copy link
Contributor

@Sisyph Sisyph left a comment

Choose a reason for hiding this comment

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

My interpretation of the comment is: some immediates are inlinable and some are not. So if we had an inlinable constant in the mandatory literal operand slot of the instruction, we want to commute the operands so the one that is inlinable is in the inlinable slot.

As to whether it's for some reason dead code, I can't say.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/delete-dead-s-fmaak-fmamk-folding-code branch from 5681ced to 3a748a7 Compare May 21, 2025 10:01
@jayfoad
Copy link
Contributor

jayfoad commented May 21, 2025

No tests fail with this.

That's because the three cases that were supposed to exercise this code in test/CodeGen/AMDGPU/fold-operands-scalar-fmac.mir are exactly the ones that were previously pessimized by #127626.

@mbrkusanin
Copy link
Collaborator

Cases that this was supposed to cover can no longer happen in this part of the code due to #127563 and #127626.

@mbrkusanin
Copy link
Collaborator

Cases that this was supposed to cover can no longer happen in this part of the code due to #127563 and #127626.

We used to prefer s_fmamk and s_fmamk over s_fmac with inlinable constants because they had untied src2 from dst.
This code was working with cases where inlinable constant was in the literal slot of fmamk or fmaak and we wanted to fold another noninlinable one.

Either way due to other changes this can no longer be used in the same way.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/delete-dead-s-fmaak-fmamk-folding-code branch 2 times, most recently from 81a1b9f to 024b6d6 Compare May 27, 2025 16:02
Copy link
Contributor Author

arsenm commented May 29, 2025

Merge activity

  • May 29, 5:28 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 29, 5:31 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 29, 5:33 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 29, 5:36 PM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/delete-dead-s-fmaak-fmamk-folding-code branch from 024b6d6 to 5e1ede7 Compare May 29, 2025 17:30
No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.
@arsenm arsenm force-pushed the users/arsenm/amdgpu/delete-dead-s-fmaak-fmamk-folding-code branch from 5e1ede7 to 62c750f Compare May 29, 2025 17:33
@arsenm arsenm merged commit 1b07c58 into main May 29, 2025
6 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/delete-dead-s-fmaak-fmamk-folding-code branch May 29, 2025 17:36
svkeerthy pushed a commit that referenced this pull request May 29, 2025
…140580)

No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
…lvm#140580)

No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…lvm#140580)

No tests fail with this. I'm not sure I understand the comment,
there can't be any folding into an operand that had to already
be a constant. I tried different combinations of immediates to these
instructions but never hit the condition.
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.

5 participants