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 makes sure we are extracting the found similarity sections
5 ; correctly at the call site.
7 define void @extract1() {
8 ; CHECK-LABEL: @extract1(
10 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
11 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
12 ; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4
13 ; CHECK-NEXT: call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* [[C]])
14 ; CHECK-NEXT: ret void
17 %a = alloca i32, align 4
18 %b = alloca i32, align 4
19 %c = alloca i32, align 4
20 store i32 2, i32* %a, align 4
21 store i32 3, i32* %b, align 4
22 store i32 4, i32* %c, align 4
23 %al = load i32, i32* %a
24 %bl = load i32, i32* %b
25 %cl = load i32, i32* %c
29 define void @extract2() {
30 ; CHECK-LABEL: @extract2(
32 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
33 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
34 ; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4
35 ; CHECK-NEXT: call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* [[C]])
36 ; CHECK-NEXT: ret void
39 %a = alloca i32, align 4
40 %b = alloca i32, align 4
41 %c = alloca i32, align 4
42 store i32 2, i32* %a, align 4
43 store i32 3, i32* %b, align 4
44 store i32 4, i32* %c, align 4
45 %al = load i32, i32* %a
46 %bl = load i32, i32* %b
47 %cl = load i32, i32* %c
51 ; There are potential ouptuts in this sections, but we do not extract sections
52 ; with outputs right now, since they cannot be consolidated.
53 define void @extract_outs1() #0 {
54 ; CHECK-LABEL: @extract_outs1(
56 ; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
57 ; CHECK-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4
58 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
59 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
60 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
61 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
62 ; CHECK-NEXT: [[LT_CAST:%.*]] = bitcast i32* [[ADD_LOC]] to i8*
63 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST]])
64 ; CHECK-NEXT: [[LT_CAST1:%.*]] = bitcast i32* [[DOTLOC]] to i8*
65 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST1]])
66 ; CHECK-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]], i32* [[OUTPUT]], i32* [[ADD_LOC]], i32* [[DOTLOC]])
67 ; CHECK-NEXT: [[ADD_RELOAD:%.*]] = load i32, i32* [[ADD_LOC]], align 4
68 ; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, i32* [[DOTLOC]], align 4
69 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST]])
70 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST1]])
71 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[OUTPUT]], align 4
72 ; CHECK-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], i32* [[RESULT]])
73 ; CHECK-NEXT: ret void
76 %a = alloca i32, align 4
77 %b = alloca i32, align 4
78 %output = alloca i32, align 4
79 %result = alloca i32, align 4
80 store i32 2, i32* %a, align 4
81 store i32 3, i32* %b, align 4
82 %0 = load i32, i32* %a, align 4
83 %1 = load i32, i32* %b, align 4
85 store i32 %add, i32* %output, align 4
86 %2 = load i32, i32* %output, align 4
87 %3 = load i32, i32* %output, align 4
88 %mul = mul i32 %2, %add
89 store i32 %mul, i32* %result, align 4
93 ; There are potential ouptuts in this sections, but we do not extract sections
94 ; with outputs right now, since they cannot be consolidated.
95 define void @extract_outs2() #0 {
96 ; CHECK-LABEL: @extract_outs2(
98 ; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
99 ; CHECK-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4
100 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
101 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
102 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
103 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
104 ; CHECK-NEXT: [[LT_CAST:%.*]] = bitcast i32* [[ADD_LOC]] to i8*
105 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST]])
106 ; CHECK-NEXT: [[LT_CAST1:%.*]] = bitcast i32* [[DOTLOC]] to i8*
107 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST1]])
108 ; CHECK-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]], i32* [[OUTPUT]], i32* [[ADD_LOC]], i32* [[DOTLOC]])
109 ; CHECK-NEXT: [[ADD_RELOAD:%.*]] = load i32, i32* [[ADD_LOC]], align 4
110 ; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, i32* [[DOTLOC]], align 4
111 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST]])
112 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST1]])
113 ; CHECK-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], i32* [[RESULT]])
114 ; CHECK-NEXT: ret void
117 %a = alloca i32, align 4
118 %b = alloca i32, align 4
119 %output = alloca i32, align 4
120 %result = alloca i32, align 4
121 store i32 2, i32* %a, align 4
122 store i32 3, i32* %b, align 4
123 %0 = load i32, i32* %a, align 4
124 %1 = load i32, i32* %b, align 4
125 %add = add i32 %0, %1
126 store i32 %add, i32* %output, align 4
127 %2 = load i32, i32* %output, align 4
128 %mul = mul i32 %2, %add
129 store i32 %mul, i32* %result, align 4