[llvm] [AMDGPU] Speedup SIFormMemoryClauses live-in register set calculation. (PR #89919)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 06:04:11 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Valery Pykhtin (vpykhtin)

<details>
<summary>Changes</summary>

GCNDownwardRPTracker requires live-in set for a start of every memory clause. The live-in set calculation is expensive calculation and instead of calculating a set for one clause at time the patch calculates all sets for all clauses at once. This is faster because start slot indexes for clauses are ordered and LIS live segments for a register are also ordered so the getLiveRegMap finds a range of start slot indexes that fall into a given live segment of a register.

This patch uses the same approach used in GCNScheduleDAGMILive::getBBLiveInMap

---
Full diff: https://github.com/llvm/llvm-project/pull/89919.diff


1 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp (+26-8) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp b/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
index edcfd994033e79..b496c8d449edf2 100644
--- a/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
@@ -275,10 +275,29 @@ bool SIFormMemoryClauses::runOnMachineFunction(MachineFunction &MF) {
   unsigned FuncMaxClause = MF.getFunction().getFnAttributeAsParsedInteger(
       "amdgpu-max-memory-clause", MaxClause);
 
-  for (MachineBasicBlock &MBB : MF) {
-    GCNDownwardRPTracker RPT(*LIS);
+  SmallVector<MachineInstr *, 16> FirstBBClauseMI;
+  for (auto &MBB : MF) {
+    for (auto &MI : MBB) {
+      if (!MI.isMetaInstruction() &&
+          isValidClauseInst(MI, isVMEMClauseInst(MI))) {
+        FirstBBClauseMI.push_back(&MI);
+        break;
+      }
+    }
+  }
+  if (FirstBBClauseMI.empty())
+    return false;
+
+  auto LRM = getLiveRegMap(FirstBBClauseMI, false /*After*/, *LIS);
+
+  GCNDownwardRPTracker RPT(*LIS);
+  for (auto *FirstMI : FirstBBClauseMI) {
+    auto &MBB = *FirstMI->getParent();
+    RPT.reset(*FirstMI, &LRM[FirstMI]);
     MachineBasicBlock::instr_iterator Next;
-    for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; I = Next) {
+    for (auto I = MachineBasicBlock::instr_iterator(FirstMI),
+              E = MBB.instr_end();
+         I != E; I = Next) {
       MachineInstr &MI = *I;
       Next = std::next(I);
 
@@ -287,12 +306,11 @@ bool SIFormMemoryClauses::runOnMachineFunction(MachineFunction &MF) {
 
       bool IsVMEM = isVMEMClauseInst(MI);
 
-      if (!isValidClauseInst(MI, IsVMEM))
-        continue;
+      if (&MI != FirstMI) {
+        if (!isValidClauseInst(MI, IsVMEM))
+          continue;
 
-      if (!RPT.getNext().isValid())
-        RPT.reset(MI);
-      else { // Advance the state to the current MI.
+        // Advance the state to the current MI.
         RPT.advance(MachineBasicBlock::const_iterator(MI));
         RPT.advanceBeforeNext();
       }

``````````

</details>


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


More information about the llvm-commits mailing list