[llvm] [AMDGPU] Improve isBasicBlockPrologue to only add necessary instructions (PR #113303)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 11:06:53 PDT 2024


================
@@ -8901,6 +8901,22 @@ unsigned SIInstrInfo::getLiveRangeSplitOpcode(Register SrcReg,
   return AMDGPU::COPY;
 }
 
+bool SIInstrInfo::isPrologueOperandReload(const MachineInstr &MI) const {
+  unsigned Opcode = MI.getOpcode();
+  if ((isSGPRSpill(MI) &&
+       (MI.mayLoad() || Opcode == AMDGPU::SI_RESTORE_S32_FROM_VGPR)) ||
+      (isWWMRegSpillOpcode(Opcode) && MI.mayLoad())) {
+    Register Reg = MI.defs().begin()->getReg();
+    const MachineBasicBlock *MBB = MI.getParent();
+    MachineBasicBlock::const_instr_iterator I(MI), E = MBB->instr_end();
+    while (++I != E) {
+      if (I->readsRegister(Reg, &RI) && isBasicBlockPrologue(*I))
----------------
alex-t wrote:

The initial idea was: to add to the prologue only those providing operands for other prologue instruction. So, it is naturally recursive. SIInstrInfo is stateless so we rematerialize the value "is prologue" for each instruction each time the function is called. We could avoid recursion if we have an MI flag isPrologue which could be computed and set once but cleared in clone/copy operations.


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


More information about the llvm-commits mailing list