[llvm] [AMDGPU] Do not fold an immediate into instructions with frame indexes (PR #151263)

Changpeng Fang via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 5 10:07:16 PDT 2025


================
@@ -6120,10 +6120,11 @@ bool SIInstrInfo::isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
           !Op.isIdenticalTo(*MO))
         return false;
 
-      // Do not fold a frame index into an instruction that already has a frame
-      // index. The frame index handling code doesn't handle fixing up operand
-      // constraints if there are multiple indexes.
-      if (Op.isFI() && MO->isFI())
+      // Do not fold a frame index or an immediate into an instruction that
+      // already has a frame index. The frame index handling code doesn't handle
+      // fixing up operand constraints if there are multiple indexes, and a
+      // frame index could possibly turn out to be another immediate.
+      if (Op.isFI() && (MO->isFI() || MO->isImm()))
----------------
changpeng wrote:

> This probably should be !isReg, the same issue probably exists for any exotic operand types
we are under the following conditions. So it means completely giving up when the instruction has a FI operand.
 if (!IsInlineConst && !MO->isReg() && isSALU(MI)) {

https://github.com/llvm/llvm-project/pull/151263


More information about the llvm-commits mailing list