1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=hotcoldsplit -hotcoldsplit-threshold=0 < %s 2>&1 | FileCheck %s
4 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
6 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
8 declare void @cold_use(ptr) cold
10 declare void @use(ptr)
12 ; In this CFG, splitting will extract the blocks extract{1,2}. I.e., it will
13 ; extract a lifetime.start marker, but not the corresponding lifetime.end
14 ; marker. Make sure that a lifetime.start marker is emitted before the call to
15 ; the split function, and *only* that marker.
19 ; extract1 no-extract1
28 ; After splitting, we should see:
32 ; codeRepl no-extract1
37 define void @only_lifetime_start_is_cold() {
38 ; CHECK-LABEL: @only_lifetime_start_is_cold(
40 ; CHECK-NEXT: [[LOCAL1:%.*]] = alloca i256
41 ; CHECK-NEXT: br i1 undef, label [[CODEREPL:%.*]], label [[NO_EXTRACT1:%.*]]
43 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[LOCAL1]])
44 ; CHECK-NEXT: [[TARGETBLOCK:%.*]] = call i1 @only_lifetime_start_is_cold.cold.1(ptr [[LOCAL1]]) #3
45 ; CHECK-NEXT: br i1 [[TARGETBLOCK]], label [[NO_EXTRACT1]], label [[EXIT:%.*]]
47 ; CHECK-NEXT: br label [[EXIT]]
49 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 1, ptr [[LOCAL1]])
50 ; CHECK-NEXT: ret void
54 br i1 undef, label %extract1, label %no-extract1
58 call void @llvm.lifetime.start.p0(i64 1, ptr %local1)
59 call void @cold_use(ptr %local1)
60 br i1 undef, label %extract2, label %no-extract1
70 call void @llvm.lifetime.end.p0(i64 1, ptr %local1)
74 ; In this CFG, splitting will extract the block extract1. I.e., it will extract
75 ; a lifetime.end marker, but not the corresponding lifetime.start marker. Do
76 ; not emit a lifetime.end marker after the call to the split function.
81 ; no-extract1 extract1
86 ; After splitting, we should see:
91 ; no-extract1 codeRepl
95 define void @only_lifetime_end_is_cold() {
96 ; CHECK-LABEL: @only_lifetime_end_is_cold(
98 ; CHECK-NEXT: [[LOCAL1:%.*]] = alloca i256
99 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 1, ptr [[LOCAL1]])
100 ; CHECK-NEXT: br i1 undef, label [[NO_EXTRACT1:%.*]], label [[CODEREPL:%.*]]
101 ; CHECK: no-extract1:
102 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 1, ptr [[LOCAL1]])
103 ; CHECK-NEXT: br label [[EXIT:%.*]]
105 ; CHECK-NEXT: call void @only_lifetime_end_is_cold.cold.1(ptr [[LOCAL1]]) #3
106 ; CHECK-NEXT: br label [[EXIT]]
108 ; CHECK-NEXT: ret void
112 %local1 = alloca i256
113 call void @llvm.lifetime.start.p0(i64 1, ptr %local1)
114 br i1 undef, label %no-extract1, label %extract1
118 call void @llvm.lifetime.end.p0(i64 1, ptr %local1)
123 call void @cold_use(ptr %local1)
124 call void @llvm.lifetime.end.p0(i64 1, ptr %local1)
131 ; In this CFG, splitting will extract the blocks extract{1,2,3}. Lifting the
132 ; lifetime.end marker would be a miscompile.
133 define void @do_not_lift_lifetime_end() {
134 ; CHECK-LABEL: @do_not_lift_lifetime_end(
136 ; CHECK-NEXT: [[LOCAL1:%.*]] = alloca i256
137 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 1, ptr [[LOCAL1]])
138 ; CHECK-NEXT: br label [[HEADER:%.*]]
140 ; CHECK-NEXT: call void @use(ptr [[LOCAL1]])
141 ; CHECK-NEXT: br i1 undef, label [[EXIT:%.*]], label [[CODEREPL:%.*]]
143 ; CHECK-NEXT: [[TARGETBLOCK:%.*]] = call i1 @do_not_lift_lifetime_end.cold.1(ptr [[LOCAL1]]) #3
144 ; CHECK-NEXT: br i1 [[TARGETBLOCK]], label [[HEADER]], label [[EXIT]]
146 ; CHECK-NEXT: ret void
150 %local1 = alloca i256
151 call void @llvm.lifetime.start.p0(i64 1, ptr %local1)
155 ; If the lifetime.end marker is lifted, this use becomes dead the second time
156 ; the header block is executed.
157 call void @use(ptr %local1)
158 br i1 undef, label %exit, label %extract1
161 call void @cold_use(ptr %local1)
162 br i1 undef, label %extract2, label %extract3
170 call void @llvm.lifetime.end.p0(i64 1, ptr %local1)