blob: e3c558a09b3564ed7079c52db74a77bfd64cecad [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -passes=lcssa -S %s | FileCheck %s
; Lifetime markers must point directly to allocas. If an alloca is defined in
; a loop and a marker uses it outside the loop, LCSSA must drop all of the
; alloca's lifetime markers instead of rewriting one through a PHI.
define void @drop_lifetime_markers(i1 %repeat) {
; CHECK-LABEL: define void @drop_lifetime_markers(
; CHECK-SAME: i1 [[REPEAT:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[STORAGE:%.*]] = alloca i8, align 1
; CHECK-NEXT: br i1 [[REPEAT]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret void
;
entry:
br label %loop
loop:
%storage = alloca i8
call void @llvm.lifetime.start.p0(ptr %storage)
br i1 %repeat, label %loop, label %exit
exit:
call void @llvm.lifetime.end.p0(ptr %storage)
ret void
}
; If all lifetime markers stay inside the loop, preserve them even when another
; use of the alloca requires an LCSSA PHI.
define ptr @preserve_lifetime_markers(i1 %repeat) {
; CHECK-LABEL: define ptr @preserve_lifetime_markers(
; CHECK-SAME: i1 [[REPEAT:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[STORAGE:%.*]] = alloca i8, align 1
; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[STORAGE]])
; CHECK-NEXT: call void @llvm.lifetime.end.p0(ptr [[STORAGE]])
; CHECK-NEXT: br i1 [[REPEAT]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[STORAGE_LCSSA:%.*]] = phi ptr [ [[STORAGE]], %[[LOOP]] ]
; CHECK-NEXT: ret ptr [[STORAGE_LCSSA]]
;
entry:
br label %loop
loop:
%storage = alloca i8
call void @llvm.lifetime.start.p0(ptr %storage)
call void @llvm.lifetime.end.p0(ptr %storage)
br i1 %repeat, label %loop, label %exit
exit:
ret ptr %storage
}