[PATCH] D125699: [StackColoring] Don't merge slots with differing StackIDs

Fraser Cormack via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 08:56:04 PDT 2022


frasercrmck created this revision.
frasercrmck added reviewers: arsenm, craig.topper, MaskRay.
Herald added subscribers: luke957, StephenFan, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
Herald added a project: All.
frasercrmck requested review of this revision.
Herald added subscribers: llvm-commits, alextsao1999, pcwang-thead, wdng.
Herald added a project: LLVM.

The documentation for this specifically mentions that this should not
happen. We could think about adding target hooks to permit it (and how
to merge IDs) in the future if that is desirable.

This specific test case was merging a scalable-vector slot into a
non-scalable one and dropping the notion of scalability, meaning we
failed to allocate enough stack space for the object.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125699

Files:
  llvm/lib/CodeGen/StackColoring.cpp
  llvm/test/CodeGen/RISCV/rvv/stack-coloring-scalablevec.mir


Index: llvm/test/CodeGen/RISCV/rvv/stack-coloring-scalablevec.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/stack-coloring-scalablevec.mir
@@ -0,0 +1,39 @@
+# RUN: llc -mtriple riscv64 -mattr=+m,+v -run-pass=stack-coloring \
+# RUN:     -riscv-v-vector-bits-min=512 -o - %s | FileCheck %s
+
+# Test that a scalable slot (%stack.1) is not merged into a non-scalable one
+# (%stack.0)
+
+# CHECK:    {{^}}stack:
+# CHECK-NEXT: - { id: 0,
+# CHECK:      - { id: 1,
+
+--- |
+  define dso_local void @dont_merge() {
+  entry:
+    %buf1 = alloca <4 x i32>
+    %buf2 = alloca <vscale x 4 x i32>
+    ret void
+  }
+
+...
+---
+name:            dont_merge
+tracksRegLiveness: true
+stack:
+  - { id: 0, name: buf1, size: 16, alignment: 16 }
+  - { id: 1, name: buf2, size: 16, alignment: 16, stack-id: scalable-vector }
+body:             |
+  bb.0.entry:
+    liveins: $v8, $v10, $x10, $x11
+
+    LIFETIME_START %stack.0
+    PseudoVSPILL_M1 killed renamable $v8, %stack.0 :: (store 16 into %stack.0, align 16)
+    renamable $v8 = PseudoVRELOAD_M1 killed $x10 :: (load 16 from %stack.0, align 16)
+    LIFETIME_END %stack.0
+    LIFETIME_START %stack.1
+    PseudoVSPILL_M2 killed renamable $v10m2, %stack.1 :: (store unknown-size into %stack.1, align 16)
+    renamable $v10m2 = PseudoVRELOAD_M2 killed $x11 :: (load unknown-size from %stack.1, align 16)
+    LIFETIME_END %stack.1
+    PseudoRET
+...
Index: llvm/lib/CodeGen/StackColoring.cpp
===================================================================
--- llvm/lib/CodeGen/StackColoring.cpp
+++ llvm/lib/CodeGen/StackColoring.cpp
@@ -1318,6 +1318,10 @@
         if (SortedSlots[J] == -1)
           continue;
 
+        // Objects with different stack IDs cannot be merged.
+        if (MFI->getStackID(SortedSlots[I]) != MFI->getStackID(SortedSlots[J]))
+          continue;
+
         int FirstSlot = SortedSlots[I];
         int SecondSlot = SortedSlots[J];
         LiveInterval *First = &*Intervals[FirstSlot];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125699.429738.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/82aeac7c/attachment.bin>


More information about the llvm-commits mailing list