[llvm] [AMDGPU] Fix register class constraints for si-fold-operands pass when folding immediate into copies (PR #131387)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 8 02:52:52 PDT 2025
================
@@ -1047,6 +1047,16 @@ void SIFoldOperandsImpl::foldOperand(
if (MovOp == AMDGPU::COPY)
return;
+ // Fold if the destination register class of the MOV instruction (ResRC)
+ // is a superclass of (or equal to) the destination register class of the COPY (DestRC).
+ // If this condition fails, folding would be illegal.
+ const MCInstrDesc &MovDesc = TII->get(MovOp);
+ if (MovDesc.getNumDefs() > 0 && MovDesc.operands()[0].RegClass != -1) {
+ const TargetRegisterClass *ResRC =
+ TRI->getRegClass(MovDesc.operands()[0].RegClass);
+ if (!DestRC -> hasSuperClassEq(ResRC)) return;
----------------
arsenm wrote:
Can you use getCommonSubClass or getMatchingSuperRegClass instead of directly checking hasSuperClassEq
https://github.com/llvm/llvm-project/pull/131387
More information about the llvm-commits
mailing list