[llvm-branch-commits] [llvm] AMDGPU: Fold inline immediates in peephole-opt (PR #208423)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 9 04:58:36 PDT 2026
================
@@ -3899,9 +3915,41 @@ bool SIInstrInfo::foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
return true;
}
+
+ return false;
}
- return false;
+ // Early exit for generic instructions which will never fold an immediate.
+ if (!isTargetSpecificOpcode(UseMI.getOpcode()))
+ return false;
+
+ // Directly fold inline immediates into the uses. These should be free-ish
+ // regardless of the uses.
+ bool FoldedInlineImm = false;
+
+ for (MachineOperand &UseMO : UseMI.explicit_uses()) {
+ if (!UseMO.isReg() || UseMO.getReg() != Reg)
+ continue;
+
+ unsigned UseOpIdx = UseMO.getOperandNo();
+
+ int64_t ImmVal = Imm;
+ if (unsigned UseSubReg = UseMO.getSubReg()) {
+ std::optional<int64_t> SubImm = extractSubregFromImm(Imm, UseSubReg);
+ if (!SubImm)
+ continue;
+ ImmVal = *SubImm;
+ }
+
+ if (!isInlineConstant(UseMI, UseOpIdx, ImmVal))
+ continue;
+
+ UseMO.ChangeToImmediate(ImmVal);
+ FoldedInlineImm = true;
+ }
+
+ // TODO: Consider applying tryConstantFoldOp here
----------------
arsenm wrote:
Because that is a large amount of patch scope creep. It requires moving and possibly removing the existing fold from SIFoldOperands
https://github.com/llvm/llvm-project/pull/208423
More information about the llvm-branch-commits
mailing list