1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -verify -iroutliner -ir-outlining-no-cost < %s | FileCheck %s
4 ; This test ensures that an extra output is not added when there is a bitcast
5 ; that is relocated to outside of the extraction due to a starting lifetime
6 ; instruction outside of the extracted region.
8 ; Additionally, we check that the newly added bitcast instruction is excluded in
11 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
12 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
14 define void @outline_bitcast_base() {
15 ; CHECK-LABEL: @outline_bitcast_base(
17 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
18 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
19 ; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4
20 ; CHECK-NEXT: [[D:%.*]] = alloca i32, align 4
21 ; CHECK-NEXT: call void @[[FUNCTION_0:.*]](i32* [[A]], i32* [[B]], i32* [[C]], i32* [[D]])
22 ; CHECK-NEXT: ret void
25 %a = alloca i32, align 4
26 %b = alloca i32, align 4
27 %c = alloca i32, align 4
28 %d = alloca i32, align 4
29 store i32 2, i32* %a, align 4
30 store i32 3, i32* %b, align 4
31 store i32 4, i32* %c, align 4
32 %X = bitcast i32* %d to i8*
33 %al = load i32, i32* %a
34 %bl = load i32, i32* %b
35 %cl = load i32, i32* %c
39 define void @outline_bitcast_removed() {
40 ; CHECK-LABEL: @outline_bitcast_removed(
42 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
43 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
44 ; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4
45 ; CHECK-NEXT: [[D:%.*]] = alloca i32, align 4
46 ; CHECK-NEXT: call void @[[FUNCTION_0:.*]](i32* [[A]], i32* [[B]], i32* [[C]], i32* [[D]])
47 ; CHECK-NEXT: [[LT_CAST1:%.*]] = bitcast i32* [[D]] to i8*
48 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST1]])
49 ; CHECK-NEXT: [[AM:%.*]] = load i32, i32* [[B]], align 4
50 ; CHECK-NEXT: [[BM:%.*]] = load i32, i32* [[A]], align 4
51 ; CHECK-NEXT: [[CM:%.*]] = load i32, i32* [[C]], align 4
52 ; CHECK-NEXT: [[AS:%.*]] = add i32 [[AM]], [[BM]]
53 ; CHECK-NEXT: [[BS:%.*]] = add i32 [[BM]], [[AM]]
54 ; CHECK-NEXT: [[CS:%.*]] = add i32 [[BM]], [[CM]]
55 ; CHECK-NEXT: [[LT_CAST:%.*]] = bitcast i32* [[D]] to i8*
56 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST]])
57 ; CHECK-NEXT: ret void
60 %a = alloca i32, align 4
61 %b = alloca i32, align 4
62 %c = alloca i32, align 4
63 %d = alloca i32, align 4
64 store i32 2, i32* %a, align 4
65 store i32 3, i32* %b, align 4
66 store i32 4, i32* %c, align 4
67 %X = bitcast i32* %d to i8*
68 %al = load i32, i32* %a
69 %bl = load i32, i32* %b
70 %cl = load i32, i32* %c
71 call void @llvm.lifetime.start.p0i8(i64 -1, i8* %X)
72 %am = load i32, i32* %b
73 %bm = load i32, i32* %a
74 %cm = load i32, i32* %c
75 %as = add i32 %am, %bm
76 %bs = add i32 %bm, %am
77 %cs = add i32 %bm, %cm
78 call void @llvm.lifetime.end.p0i8(i64 -1, i8* %X)
82 define void @outline_bitcast_base2(i32 %a, i32 %b, i32 %c) {
83 ; CHECK-LABEL: @outline_bitcast_base2(
85 ; CHECK-NEXT: [[AL:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
86 ; CHECK-NEXT: [[BL:%.*]] = add i32 [[B]], [[A]]
87 ; CHECK-NEXT: [[CL:%.*]] = add i32 [[B]], [[C:%.*]]
88 ; CHECK-NEXT: ret void
97 ; CHECK: define internal void @[[FUNCTION_0]](i32* [[ARG0:%.*]], i32* [[ARG1:%.*]], i32* [[ARG2:%.*]], i32* [[ARG3:%.*]])
98 ; CHECK: entry_to_outline:
99 ; CHECK-NEXT: store i32 2, i32* [[ARG0]], align 4
100 ; CHECK-NEXT: store i32 3, i32* [[ARG1]], align 4
101 ; CHECK-NEXT: store i32 4, i32* [[ARG2]], align 4
102 ; CHECK-NEXT: [[X:%.*]] = bitcast i32* [[ARG3]] to i8*
103 ; CHECK-NEXT: [[AL:%.*]] = load i32, i32* [[ARG0]], align 4
104 ; CHECK-NEXT: [[BL:%.*]] = load i32, i32* [[ARG1]], align 4
105 ; CHECK-NEXT: [[CL:%.*]] = load i32, i32* [[ARG2]], align 4