diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/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. diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/lifetime-marker-no-dce.mir b/llvm/test/CodeGen/AArch64/GlobalISel/lifetime-marker-no-dce.mir new file mode 100644 --- /dev/null +++ b/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 + +...