[PATCH] D136267: [AMDGPU] Speedup GCNDownwardRPTracker::advanceBeforeNext

Valery Pykhtin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 04:33:20 PST 2023


vpykhtin updated this revision to Diff 503732.
vpykhtin added a comment.
Herald added a subscriber: javed.absar.

- added regression test.
- rebased after the fix a999669982d0 <https://reviews.llvm.org/rGa999669982d0cedacbb7371c96fce95682d582e1>: [AMDGPU] Scheduler: fix RP calculation for a MBB with one successor


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136267/new/

https://reviews.llvm.org/D136267

Files:
  llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
  llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll


Index: llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll
@@ -0,0 +1,31 @@
+; RUN: llc -march=amdgcn -mcpu=gfx900 < %s
+
+declare void @llvm.amdgcn.kill(i1)
+declare <4 x float> @llvm.amdgcn.image.sample.2d.v4f32.f32(i32 immarg, float, float, <8 x i32>, <4 x i32>, i1 immarg, i32 immarg, i32 immarg)
+declare <2 x half> @llvm.amdgcn.cvt.pkrtz(float, float)
+declare void @llvm.amdgcn.exp.compr.v2f16(i32 immarg, i32 immarg, <2 x half>, <2 x half>, i1 immarg, i1 immarg)
+
+define amdgpu_ps void @_amdgpu_ps_main(float %arg) {
+bb:
+  %i = fcmp olt float %arg, 0.000000e+00
+  br i1 %i, label %bb5, label %bb1
+
+bb1:
+  %i2 = call <4 x float> @llvm.amdgcn.image.sample.2d.v4f32.f32(i32 15, float 0.000000e+00, float %arg, <8 x i32> zeroinitializer, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0)
+  %i3 = extractelement <4 x float> %i2, i64 1
+  %i4 = extractelement <4 x float> %i2, i64 0
+  br label %bb6
+
+bb5:
+  call void @llvm.amdgcn.kill(i1 false)
+  br label %bb6
+
+bb6:
+  %i7 = phi float [ 0.000000e+00, %bb5 ], [ %i3, %bb1 ]
+  %i8 = phi float [ 0.000000e+00, %bb5 ], [ 1.000000e+00, %bb1 ]
+  %i9 = phi float [ undef, %bb5 ], [ %i4, %bb1 ]
+  %i10 = call <2 x half> @llvm.amdgcn.cvt.pkrtz(float 0.000000e+00, float %i7)
+  %i11 = call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %i8, float %i9)
+  call void @llvm.amdgcn.exp.compr.v2f16(i32 0, i32 0, <2 x half> %i10, <2 x half> %i11, i1 false, i1 false)
+  ret void
+}
Index: llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
+++ llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
@@ -336,23 +336,38 @@
   assert(SI.isValid());
 
   // Remove dead registers or mask bits.
-  for (auto &It : LiveRegs) {
-    const LiveInterval &LI = LIS.getInterval(It.first);
+  SmallSet<Register, 8> SeenRegs;
+  for (auto &MO : LastTrackedMI->operands()) {
+    if (!MO.isReg() || !MO.getReg().isVirtual())
+      continue;
+    if (MO.isUse() && !MO.readsReg())
+      continue;
+    if (!SeenRegs.insert(MO.getReg()).second)
+      continue;
+    const LiveInterval &LI = LIS.getInterval(MO.getReg());
     if (LI.hasSubRanges()) {
+      auto It = LiveRegs.end();
       for (const auto &S : LI.subranges()) {
         if (!S.liveAt(SI)) {
-          auto PrevMask = It.second;
-          It.second &= ~S.LaneMask;
-          CurPressure.inc(It.first, PrevMask, It.second, *MRI);
+          if (It == LiveRegs.end()) {
+            It = LiveRegs.find(MO.getReg());
+            if (It == LiveRegs.end())
+              llvm_unreachable("register isn't live");
+          }
+          auto PrevMask = It->second;
+          It->second &= ~S.LaneMask;
+          CurPressure.inc(MO.getReg(), PrevMask, It->second, *MRI);
         }
       }
+      if (It != LiveRegs.end() && It->second.none())
+        LiveRegs.erase(It);
     } else if (!LI.liveAt(SI)) {
-      auto PrevMask = It.second;
-      It.second = LaneBitmask::getNone();
-      CurPressure.inc(It.first, PrevMask, It.second, *MRI);
+      auto It = LiveRegs.find(MO.getReg());
+      if (It == LiveRegs.end())
+        llvm_unreachable("register isn't live");
+      CurPressure.inc(MO.getReg(), It->second, LaneBitmask::getNone(), *MRI);
+      LiveRegs.erase(It);
     }
-    if (It.second.none())
-      LiveRegs.erase(It.first);
   }
 
   MaxPressure = max(MaxPressure, CurPressure);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136267.503732.patch
Type: text/x-patch
Size: 3598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230309/462abb51/attachment-0001.bin>


More information about the llvm-commits mailing list