[PATCH] D98811: [GlobalISel] Don't DCE LIFETIME_START/LIFETIME_END markers.

Amara Emerson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 17 13:29:47 PDT 2021


aemerson created this revision.
aemerson added reviewers: paquette, arsenm.
aemerson added a project: LLVM.
Herald added subscribers: hiraditya, rovka.
aemerson requested review of this revision.
Herald added a subscriber: wdng.

These are pseudos without any users, so DCE was killing them in the combiner.

Marking them as having side effects doesn't seem quite right since they don't.

Gives a nice 0.3% geomean size win on CTMark -Os.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98811

Files:
  llvm/lib/CodeGen/GlobalISel/Utils.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/lifetime-marker-no-dce.mir


Index: llvm/test/CodeGen/AArch64/GlobalISel/lifetime-marker-no-dce.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/GlobalISel/lifetime-marker-no-dce.mir
@@ -0,0 +1,43 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -run-pass=aarch64-prelegalizer-combiner -global-isel -verify-machineinstrs %s -o - | FileCheck %s
+# Check that we don't DCE the lifetime markers even though they don't have any users.
+--- |
+  target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+  target triple = "aarch64"
+
+  declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
+  declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
+
+  define void @test_lifetime_no_dce() {
+    %slot = alloca i8, i32 4, align 4
+    call void @llvm.lifetime.start.p0i8(i64 0, i8* %slot)
+    call void @llvm.lifetime.end.p0i8(i64 0, i8* %slot)
+    ret void
+  }
+
+  attributes #0 = { argmemonly nofree nosync nounwind willreturn }
+
+...
+---
+name:            test_lifetime_no_dce
+alignment:       4
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: _ }
+frameInfo:
+  maxAlignment:    4
+stack:
+  - { id: 0, name: slot, size: 4, alignment: 4 }
+machineFunctionInfo: {}
+body:             |
+  bb.1 (%ir-block.0):
+    ; CHECK-LABEL: name: test_lifetime_no_dce
+    ; CHECK: LIFETIME_START %stack.0.slot
+    ; CHECK: LIFETIME_END %stack.0.slot
+    ; CHECK: RET_ReallyLR
+    %0:_(p0) = G_FRAME_INDEX %stack.0.slot
+    LIFETIME_START %stack.0.slot
+    LIFETIME_END %stack.0.slot
+    RET_ReallyLR
+
+...
Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -200,6 +200,10 @@
   // Don't delete frame allocation labels.
   if (MI.getOpcode() == TargetOpcode::LOCAL_ESCAPE)
     return false;
+  // LIFETIME markers should be preserved even if they seem dead.
+  if (MI.getOpcode() == TargetOpcode::LIFETIME_START ||
+      MI.getOpcode() == TargetOpcode::LIFETIME_END)
+    return false;
 
   // If we can move an instruction, we can remove it.  Otherwise, it has
   // a side-effect of some sort.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98811.331356.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210317/538b8a45/attachment.bin>


More information about the llvm-commits mailing list