xref: /llvm-project/llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (revision f4b925ee7078f058602fd323e25f45f1ae91ca34)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs
2; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s
3
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.
7
8; Additionally, we check that the newly added bitcast instruction is excluded in
9; further extractions.
10
11declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
12declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
13
14define void @outline_bitcast_base() {
15entry:
16  %a = alloca i32, align 4
17  %b = alloca i32, align 4
18  %c = alloca i32, align 4
19  %d = alloca i32, align 4
20  store i32 2, ptr %a, align 4
21  store i32 3, ptr %b, align 4
22  store i32 4, ptr %c, align 4
23  %al = load i32, ptr %a
24  %bl = load i32, ptr %b
25  %cl = load i32, ptr %c
26  ret void
27}
28
29define void @outline_bitcast_removed() {
30entry:
31  %a = alloca i32, align 4
32  %b = alloca i32, align 4
33  %c = alloca i32, align 4
34  %d = alloca i32, align 4
35  store i32 2, ptr %a, align 4
36  store i32 3, ptr %b, align 4
37  store i32 4, ptr %c, align 4
38  %al = load i32, ptr %a
39  %bl = load i32, ptr %b
40  %cl = load i32, ptr %c
41  call void @llvm.lifetime.start.p0(i64 -1, ptr %d)
42  %am = load i32, ptr %b
43  %bm = load i32, ptr %a
44  %cm = load i32, ptr %c
45  call void @llvm.lifetime.end.p0(i64 -1, ptr %d)
46  ret void
47}
48
49; The first bitcast is moved down to lifetime start, and, since the original
50; endpoint does not match the new endpoint, we cannot extract and outline the
51; second bitcast and set of adds.  Outlining only occurs in this case due to
52; the lack of a cost model, as denoted by the debug command line argument.
53
54define void @outline_bitcast_base2(i32 %a, i32 %b, i32 %c) {
55entry:
56  %d = alloca i32, align 4
57  %al = add i32 %a, %b
58  %bl = add i32 %b, %a
59  %cl = add i32 %b, %c
60  %buffer = mul i32 %a, %b
61  %am = add i32 %a, %b
62  %bm = add i32 %b, %a
63  %cm = add i32 %b, %c
64  call void @llvm.lifetime.start.p0(i64 -1, ptr %d)
65  call void @llvm.lifetime.end.p0(i64 -1, ptr %d)
66  ret void
67}
68
69; CHECK-LABEL: @outline_bitcast_base(
70; CHECK-NEXT:  entry:
71; CHECK-NEXT:    [[A:%.*]] = alloca i32, align 4
72; CHECK-NEXT:    [[B:%.*]] = alloca i32, align 4
73; CHECK-NEXT:    [[C:%.*]] = alloca i32, align 4
74; CHECK-NEXT:    [[D:%.*]] = alloca i32, align 4
75; CHECK-NEXT:    call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[C]])
76; CHECK-NEXT:    ret void
77;
78;
79; CHECK-LABEL: @outline_bitcast_removed(
80; CHECK-NEXT:  entry:
81; CHECK-NEXT:    [[A:%.*]] = alloca i32, align 4
82; CHECK-NEXT:    [[B:%.*]] = alloca i32, align 4
83; CHECK-NEXT:    [[C:%.*]] = alloca i32, align 4
84; CHECK-NEXT:    call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[C]])
85; CHECK-NEXT:    [[AM:%.*]] = load i32, ptr [[B]], align 4
86; CHECK-NEXT:    [[BM:%.*]] = load i32, ptr [[A]], align 4
87; CHECK-NEXT:    [[CM:%.*]] = load i32, ptr [[C]], align 4
88; CHECK-NEXT:    ret void
89;
90;
91; CHECK-LABEL: @outline_bitcast_base2(
92; CHECK-NEXT:  entry:
93; CHECK-NEXT:    call void @outlined_ir_func_1(i32 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]])
94; CHECK-NEXT:    [[BUFFER:%.*]] = mul i32 [[A]], [[B]]
95; CHECK-NEXT:    call void @outlined_ir_func_1(i32 [[A]], i32 [[B]], i32 [[C]])
96; CHECK-NEXT:    ret void
97;
98;
99; CHECK-LABEL: @outlined_ir_func_0(
100; CHECK-NEXT:  newFuncRoot:
101; CHECK-NEXT:    br label [[ENTRY_TO_OUTLINE:%.*]]
102; CHECK:       entry_to_outline:
103; CHECK-NEXT:    store i32 2, ptr [[TMP0:%.*]], align 4
104; CHECK-NEXT:    store i32 3, ptr [[TMP1:%.*]], align 4
105; CHECK-NEXT:    store i32 4, ptr [[TMP2:%.*]], align 4
106; CHECK-NEXT:    [[AL:%.*]] = load i32, ptr [[TMP0]], align 4
107; CHECK-NEXT:    [[BL:%.*]] = load i32, ptr [[TMP1]], align 4
108; CHECK-NEXT:    [[CL:%.*]] = load i32, ptr [[TMP2]], align 4
109; CHECK-NEXT:    br label [[ENTRY_AFTER_OUTLINE_EXITSTUB:%.*]]
110; CHECK:       entry_after_outline.exitStub:
111; CHECK-NEXT:    ret void
112;
113;
114; CHECK-LABEL: @outlined_ir_func_1(
115; CHECK-NEXT:  newFuncRoot:
116; CHECK-NEXT:    [[D:%.*]] = alloca i32, align 4
117; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 -1, ptr [[D]])
118; CHECK-NEXT:    br label [[ENTRY_TO_OUTLINE:%.*]]
119; CHECK:       entry_to_outline:
120; CHECK-NEXT:    [[AL:%.*]] = add i32 [[TMP0:%.*]], [[TMP1:%.*]]
121; CHECK-NEXT:    [[BL:%.*]] = add i32 [[TMP1]], [[TMP0]]
122; CHECK-NEXT:    [[CL:%.*]] = add i32 [[TMP1]], [[TMP2:%.*]]
123; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 -1, ptr [[D]])
124; CHECK-NEXT:    br label [[ENTRY_AFTER_OUTLINE_EXITSTUB:%.*]]
125; CHECK:       entry_after_outline.exitStub:
126; CHECK-NEXT:    ret void
127;
128