================
@@ -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
----------------
frederik-h wrote:
Why only "consider", i.e. why not do it now?
https://github.com/llvm/llvm-project/pull/208423
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits