[PATCH] D115278: Check subrange liveness at rematerialization

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 7 13:15:51 PST 2021


rampitec created this revision.
rampitec added reviewers: arsenm, qcolombet.
Herald added subscribers: kerbowa, hiraditya, nhaehnle, jvesely, MatzeB.
rampitec requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

LiveRangeEdit::allUsesAvailableAt checks that VNI at use is the same
as at the original use slot. However, the VNI can be the same while
a specific subrange needed for use can be dead at the new index.

This patch adds subrange liveness check if there is a subreg use.

Fixes: SWDEV-312810


https://reviews.llvm.org/D115278

Files:
  llvm/lib/CodeGen/LiveRangeEdit.cpp
  llvm/test/CodeGen/AMDGPU/remat-dead-subreg.mir


Index: llvm/test/CodeGen/AMDGPU/remat-dead-subreg.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/remat-dead-subreg.mir
@@ -0,0 +1,53 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -march=amdgcn -start-before=greedy -stop-after=virtregrewriter -stress-regalloc=3 -verify-machineinstrs -o - %s | FileCheck -check-prefix=GCN %s
+
+---
+name:            dead_subreg
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+    ; GCN-LABEL: name: dead_subreg
+    ; GCN: $m0 = IMPLICIT_DEF
+    ; GCN-NEXT: renamable $sgpr0_sgpr1 = S_MOV_B64 1, implicit $m0
+    ; GCN-NEXT: renamable $sgpr1 = S_MUL_I32 renamable $sgpr1, 3
+    ; GCN-NEXT: SI_SPILL_S32_SAVE killed renamable $sgpr1, %stack.0, implicit $exec, implicit $sp_reg :: (store (s32) into %stack.0, addrspace 5)
+    ; GCN-NEXT: renamable $sgpr2 = S_MOV_B32 2, implicit $m0
+    ; GCN-NEXT: renamable $sgpr1 = S_MOV_B32 3, implicit $m0
+    ; GCN-NEXT: dead %4:vgpr_32 = V_MOV_B32_e32 $sgpr0, implicit $exec, implicit killed $sgpr2, implicit killed $sgpr1
+    ; GCN-NEXT: renamable $sgpr1 = SI_SPILL_S32_RESTORE %stack.0, implicit $exec, implicit $sp_reg :: (load (s32) from %stack.0, addrspace 5)
+    ; GCN-NEXT: dead %5:vgpr_32 = V_MOV_B32_e32 killed $sgpr1, implicit $exec
+    ; GCN-NEXT: S_NOP 0, implicit killed renamable $sgpr0
+    $m0 = IMPLICIT_DEF
+    %0:sreg_64_xexec = S_MOV_B64 1, implicit $m0
+    %1:sreg_32 = S_MUL_I32 %0.sub1:sreg_64_xexec, 3
+    %2:sreg_32 = S_MOV_B32 2, implicit $m0
+    %3:sreg_32 = S_MOV_B32 3, implicit $m0
+    %4:vgpr_32 = V_MOV_B32_e32 %0.sub0:sreg_64_xexec, implicit $exec, implicit %2, implicit %3
+    %5:vgpr_32 = V_MOV_B32_e32 %1:sreg_32, implicit $exec
+    S_NOP 0, implicit %0.sub0
+...
+---
+name:            live_subreg
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+    ; GCN-LABEL: name: live_subreg
+    ; GCN: $m0 = IMPLICIT_DEF
+    ; GCN-NEXT: renamable $sgpr4_sgpr5 = S_MOV_B64 1, implicit $m0
+    ; GCN-NEXT: renamable $sgpr2 = S_MOV_B32 2, implicit $m0
+    ; GCN-NEXT: SI_SPILL_S32_SAVE killed renamable $sgpr2, %stack.0, implicit $exec, implicit $sp_reg :: (store (s32) into %stack.0, addrspace 5)
+    ; GCN-NEXT: renamable $sgpr2 = S_MOV_B32 3, implicit $m0
+    ; GCN-NEXT: renamable $sgpr0 = SI_SPILL_S32_RESTORE %stack.0, implicit $exec, implicit $sp_reg :: (load (s32) from %stack.0, addrspace 5)
+    ; GCN-NEXT: dead %4:vgpr_32 = V_MOV_B32_e32 $sgpr4, implicit $exec, implicit killed $sgpr0, implicit killed $sgpr2
+    ; GCN-NEXT: renamable $sgpr0 = S_MUL_I32 renamable $sgpr5, 3
+    ; GCN-NEXT: dead %5:vgpr_32 = V_MOV_B32_e32 killed $sgpr0, implicit $exec
+    ; GCN-NEXT: S_NOP 0, implicit killed renamable $sgpr5
+    $m0 = IMPLICIT_DEF
+    %0:sreg_64_xexec = S_MOV_B64 1, implicit $m0
+    %1:sreg_32 = S_MUL_I32 %0.sub1:sreg_64_xexec, 3
+    %2:sreg_32 = S_MOV_B32 2, implicit $m0
+    %3:sreg_32 = S_MOV_B32 3, implicit $m0
+    %4:vgpr_32 = V_MOV_B32_e32 %0.sub0:sreg_64_xexec, implicit $exec, implicit %2, implicit %3
+    %5:vgpr_32 = V_MOV_B32_e32 %1:sreg_32, implicit $exec
+    S_NOP 0, implicit %0.sub1
+...
Index: llvm/lib/CodeGen/LiveRangeEdit.cpp
===================================================================
--- llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -133,6 +133,21 @@
 
     if (OVNI != li.getVNInfoAt(UseIdx))
       return false;
+
+    // Check that subrange is live at UseIdx.
+    if (MO.getSubReg()) {
+      const TargetRegisterInfo *TRI = MRI.getTargetRegisterInfo();
+      LaneBitmask LM = TRI->getSubRegIndexLaneMask(MO.getSubReg());
+      for (LiveInterval::SubRange &SR : li.subranges()) {
+        if ((SR.LaneMask & LM).none() || SR.liveAt(UseIdx))
+          continue;
+        if (!SR.liveAt(UseIdx))
+          return false;
+        LM = LM & ~SR.LaneMask;
+        if (LM.none())
+          break;
+      }
+    }
   }
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115278.392513.patch
Type: text/x-patch
Size: 3992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211207/23e6cbaf/attachment-0001.bin>


More information about the llvm-commits mailing list