1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -verify -iroutliner < %s | FileCheck %s
3 ; RUN: opt -S -verify -iroutliner -ir-outlining-no-cost < %s | FileCheck %s -check-prefix=NOCOST
5 ; This test checks that we have different results from when the cost model
6 ; is on versus when it is off. That is, if the number of instructions needed to
7 ; handle the arguments is greater than the number of instructions being added,
10 define void @function1() #0 {
11 ; CHECK-LABEL: @function1(
13 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
14 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
15 ; CHECK-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]])
16 ; CHECK-NEXT: ret void
18 ; NOCOST-LABEL: @function1(
20 ; NOCOST-NEXT: [[A:%.*]] = alloca i32, align 4
21 ; NOCOST-NEXT: [[B:%.*]] = alloca i32, align 4
22 ; NOCOST-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]])
23 ; NOCOST-NEXT: ret void
26 %a = alloca i32, align 4
27 %b = alloca i32, align 4
28 %0 = load i32, i32* %a, align 4
29 %1 = load i32, i32* %b, align 4
33 %div = sdiv i32 %0, %1
34 %add1 = add i32 %0, %1
35 %mul1 = mul i32 %0, %1
36 %sub1 = sub i32 %0, %1
37 %div1 = sdiv i32 %0, %1
38 %add2 = add i32 %0, %1
39 %mul2 = mul i32 %0, %1
40 %sub2 = sub i32 %0, %1
41 %div2 = sdiv i32 %0, %1
45 define void @function2() #0 {
46 ; CHECK-LABEL: @function2(
48 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
49 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
50 ; CHECK-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]])
51 ; CHECK-NEXT: ret void
53 ; NOCOST-LABEL: @function2(
55 ; NOCOST-NEXT: [[A:%.*]] = alloca i32, align 4
56 ; NOCOST-NEXT: [[B:%.*]] = alloca i32, align 4
57 ; NOCOST-NEXT: call void @outlined_ir_func_0(i32* [[A]], i32* [[B]])
58 ; NOCOST-NEXT: ret void
61 %a = alloca i32, align 4
62 %b = alloca i32, align 4
63 %0 = load i32, i32* %a, align 4
64 %1 = load i32, i32* %b, align 4
68 %div = sdiv i32 %0, %1
69 %add1 = add i32 %0, %1
70 %mul1 = mul i32 %0, %1
71 %sub1 = sub i32 %0, %1
72 %div1 = sdiv i32 %0, %1
73 %add2 = add i32 %0, %1
74 %mul2 = mul i32 %0, %1
75 %sub2 = sub i32 %0, %1
76 %div2 = sdiv i32 %0, %1
80 define void @function3() #0 {
81 ; CHECK-LABEL: @function3(
83 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
84 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
85 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
86 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
87 ; CHECK-NEXT: store i32 2, i32* [[A]], align 4
88 ; CHECK-NEXT: store i32 3, i32* [[B]], align 4
89 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[A]], align 4
90 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B]], align 4
91 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[TMP0]], [[TMP1]]
92 ; CHECK-NEXT: store i32 [[ADD]], i32* [[OUTPUT]], align 4
93 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[OUTPUT]], align 4
94 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[OUTPUT]], align 4
95 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[TMP2]], [[ADD]]
96 ; CHECK-NEXT: store i32 [[MUL]], i32* [[RESULT]], align 4
97 ; CHECK-NEXT: ret void
99 ; NOCOST-LABEL: @function3(
100 ; NOCOST-NEXT: entry:
101 ; NOCOST-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
102 ; NOCOST-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4
103 ; NOCOST-NEXT: [[A:%.*]] = alloca i32, align 4
104 ; NOCOST-NEXT: [[B:%.*]] = alloca i32, align 4
105 ; NOCOST-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
106 ; NOCOST-NEXT: [[RESULT:%.*]] = alloca i32, align 4
107 ; NOCOST-NEXT: [[LT_CAST:%.*]] = bitcast i32* [[ADD_LOC]] to i8*
108 ; NOCOST-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST]])
109 ; NOCOST-NEXT: [[LT_CAST1:%.*]] = bitcast i32* [[DOTLOC]] to i8*
110 ; NOCOST-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST1]])
111 ; NOCOST-NEXT: call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* [[OUTPUT]], i32* [[ADD_LOC]], i32* [[DOTLOC]])
112 ; NOCOST-NEXT: [[ADD_RELOAD:%.*]] = load i32, i32* [[ADD_LOC]], align 4
113 ; NOCOST-NEXT: [[DOTRELOAD:%.*]] = load i32, i32* [[DOTLOC]], align 4
114 ; NOCOST-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST]])
115 ; NOCOST-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST1]])
116 ; NOCOST-NEXT: [[TMP0:%.*]] = load i32, i32* [[OUTPUT]], align 4
117 ; NOCOST-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], i32* [[RESULT]])
118 ; NOCOST-NEXT: ret void
121 %a = alloca i32, align 4
122 %b = alloca i32, align 4
123 %output = alloca i32, align 4
124 %result = alloca i32, align 4
125 store i32 2, i32* %a, align 4
126 store i32 3, i32* %b, align 4
127 %0 = load i32, i32* %a, align 4
128 %1 = load i32, i32* %b, align 4
129 %add = add i32 %0, %1
130 store i32 %add, i32* %output, align 4
131 %2 = load i32, i32* %output, align 4
132 %3 = load i32, i32* %output, align 4
133 %mul = mul i32 %2, %add
134 store i32 %mul, i32* %result, align 4
138 define void @function4() #0 {
139 ; CHECK-LABEL: @function4(
141 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
142 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
143 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
144 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
145 ; CHECK-NEXT: store i32 2, i32* [[A]], align 4
146 ; CHECK-NEXT: store i32 3, i32* [[B]], align 4
147 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[A]], align 4
148 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B]], align 4
149 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[TMP0]], [[TMP1]]
150 ; CHECK-NEXT: store i32 [[ADD]], i32* [[OUTPUT]], align 4
151 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[OUTPUT]], align 4
152 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[TMP2]], [[ADD]]
153 ; CHECK-NEXT: store i32 [[MUL]], i32* [[RESULT]], align 4
154 ; CHECK-NEXT: ret void
156 ; NOCOST-LABEL: @function4(
157 ; NOCOST-NEXT: entry:
158 ; NOCOST-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
159 ; NOCOST-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4
160 ; NOCOST-NEXT: [[A:%.*]] = alloca i32, align 4
161 ; NOCOST-NEXT: [[B:%.*]] = alloca i32, align 4
162 ; NOCOST-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
163 ; NOCOST-NEXT: [[RESULT:%.*]] = alloca i32, align 4
164 ; NOCOST-NEXT: [[LT_CAST:%.*]] = bitcast i32* [[ADD_LOC]] to i8*
165 ; NOCOST-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST]])
166 ; NOCOST-NEXT: [[LT_CAST1:%.*]] = bitcast i32* [[DOTLOC]] to i8*
167 ; NOCOST-NEXT: call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[LT_CAST1]])
168 ; NOCOST-NEXT: call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* [[OUTPUT]], i32* [[ADD_LOC]], i32* [[DOTLOC]])
169 ; NOCOST-NEXT: [[ADD_RELOAD:%.*]] = load i32, i32* [[ADD_LOC]], align 4
170 ; NOCOST-NEXT: [[DOTRELOAD:%.*]] = load i32, i32* [[DOTLOC]], align 4
171 ; NOCOST-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST]])
172 ; NOCOST-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[LT_CAST1]])
173 ; NOCOST-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], i32* [[RESULT]])
174 ; NOCOST-NEXT: ret void
177 %a = alloca i32, align 4
178 %b = alloca i32, align 4
179 %output = alloca i32, align 4
180 %result = alloca i32, align 4
181 store i32 2, i32* %a, align 4
182 store i32 3, i32* %b, align 4
183 %0 = load i32, i32* %a, align 4
184 %1 = load i32, i32* %b, align 4
185 %add = add i32 %0, %1
186 store i32 %add, i32* %output, align 4
187 %2 = load i32, i32* %output, align 4
188 %mul = mul i32 %2, %add
189 store i32 %mul, i32* %result, align 4