[llvm] d9012b6 - [AMDGPU] Cache results in a bitvector for VOPDPairingMutation (#201837)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 05:07:45 PDT 2026


Author: Igor Wodiany
Date: 2026-06-08T13:07:40+01:00
New Revision: d9012b6f605589ceb81b75298cda0bd38d309d81

URL: https://github.com/llvm/llvm-project/commit/d9012b6f605589ceb81b75298cda0bd38d309d81
DIFF: https://github.com/llvm/llvm-project/commit/d9012b6f605589ceb81b75298cda0bd38d309d81.diff

LOG: [AMDGPU] Cache results in a bitvector for VOPDPairingMutation (#201837)

With this change the code no longer checks `(I, J)` pair when it is
known that `(_, J)` is not a valid VOPD instruction. The saving is
achieved by precomputing `(_, Y)` into a bitvector, that is also used by
`(_, I)` check, so the `(_, J)` check is "free".

---------

Co-authored-by: Antonio Carpio <antonio.carpio at amd.com>

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp b/llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp
index d6cf6fb37ee47..4d7a92d21e0fb 100644
--- a/llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp
@@ -284,23 +284,36 @@ struct VOPDPairingMutation : ScheduleDAGMutation {
       return;
     }
 
-    std::vector<SUnit>::iterator ISUI, JSUI;
-    for (ISUI = DAG->SUnits.begin(); ISUI != DAG->SUnits.end(); ++ISUI) {
+    BitVector VOPDCapable(DAG->SUnits.size());
+    unsigned IIdx = 0;
+    // Pre-compute whether each individual instruction can be VOPD
+    for (auto ISUI = DAG->SUnits.begin(), E = DAG->SUnits.end(); ISUI != E;
+         ++ISUI, ++IIdx) {
       const MachineInstr *IMI = ISUI->getInstr();
-      if (!shouldScheduleAdjacent(TII, ST, nullptr, *IMI))
-        continue;
-      if (!hasLessThanNumFused(*ISUI, 2))
-        continue;
+      if (shouldScheduleAdjacent(TII, ST, nullptr, *IMI) &&
+          hasLessThanNumFused(*ISUI, 2))
+        VOPDCapable[IIdx] = true;
+    }
 
-      for (JSUI = ISUI + 1; JSUI != DAG->SUnits.end(); ++JSUI) {
-        if (JSUI->isBoundaryNode())
+    IIdx = 0;
+    for (auto ISUI = DAG->SUnits.begin(), E = DAG->SUnits.end(); ISUI != E;
+         ++ISUI, ++IIdx) {
+      if (!VOPDCapable[IIdx])
+        continue;
+      const MachineInstr *IMI = ISUI->getInstr();
+      unsigned JIdx = IIdx + 1;
+      for (auto JSUI = ISUI + 1; JSUI != E; ++JSUI, ++JIdx) {
+        if (!VOPDCapable[JIdx] || JSUI->isBoundaryNode())
           continue;
         const MachineInstr *JMI = JSUI->getInstr();
         if (!hasLessThanNumFused(*JSUI, 2) ||
             !shouldScheduleAdjacent(TII, ST, IMI, *JMI))
           continue;
-        if (fuseInstructionPair(*DAG, *ISUI, *JSUI))
+        if (fuseInstructionPair(*DAG, *ISUI, *JSUI)) {
+          // Clear to prevent future checks/fusing
+          VOPDCapable[JIdx] = false;
           break;
+        }
       }
     }
     LLVM_DEBUG(dbgs() << "Completed VOPDPairingMutation\n");


        


More information about the llvm-commits mailing list