xref: /llvm-project/llvm/test/Transforms/InstCombine/simplify-libcalls-new.ll (revision 95daf1aedfe521704c601a26ad8011c6e237c38a)
1;; Test behavior of -optimize-hot-cold-new and related options.
2
3;; Check that we don't get hot/cold new calls without enabling it explicitly.
4; RUN: opt < %s -passes=instcombine -S | FileCheck %s --check-prefix=OFF
5; OFF-NOT: hot_cold_t
6; OFF-LABEL: @new_hot_cold()
7
8;; First check with the default cold and hot hint values (255 = -2).
9; RUN: opt < %s -passes=instcombine -optimize-hot-cold-new -S | FileCheck %s --check-prefix=HOTCOLD -DCOLD=1 -DHOT=-2 -DPREVHINTCOLD=7 -DPREVHINTNOTCOLD=7 -DPREVHINTHOT=7
10
11;; Next check with the non-default cold and hot hint values (200 =-56).
12; RUN: opt < %s -passes=instcombine -optimize-hot-cold-new -cold-new-hint-value=5 -hot-new-hint-value=200 -S | FileCheck %s --check-prefix=HOTCOLD -DCOLD=5 -DHOT=-56 -DPREVHINTCOLD=7 -DPREVHINTNOTCOLD=7 -DPREVHINTHOT=7
13
14;; Try again with the non-default cold and hot hint values (200 =-56), and this
15;; time specify that existing hints should be updated.
16; RUN: opt < %s -passes=instcombine -optimize-hot-cold-new -cold-new-hint-value=5 -notcold-new-hint-value=100 -hot-new-hint-value=200 -optimize-existing-hot-cold-new -S | FileCheck %s --check-prefix=HOTCOLD -DCOLD=5 -DHOT=-56 -DPREVHINTCOLD=5 -DPREVHINTNOTCOLD=100 -DPREVHINTHOT=-56
17
18;; Make sure that values not in 0..255 are flagged with an error
19; RUN: not opt < %s -passes=instcombine -optimize-hot-cold-new -cold-new-hint-value=256 -S 2>&1 | FileCheck %s --check-prefix=ERROR
20; RUN: not opt < %s -passes=instcombine -optimize-hot-cold-new -hot-new-hint-value=5000 -S 2>&1 | FileCheck %s --check-prefix=ERROR
21; ERROR: value must be in the range [0, 255]!
22
23;; Check that operator new(unsigned long) converted to
24;; operator new(unsigned long, __hot_cold_t) with a hot or cold attribute.
25; HOTCOLD-LABEL: @new()
26define void @new() {
27  ;; Attribute cold converted to __hot_cold_t cold value.
28  ; HOTCOLD: @_Znwm12__hot_cold_t(i64 10, i8 [[COLD]])
29  %call = call ptr @_Znwm(i64 10) #0
30  call void @dummy(ptr %call)
31  ;; Attribute notcold has no effect.
32  ; HOTCOLD: @_Znwm(i64 10)
33  %call1 = call ptr @_Znwm(i64 10) #1
34  call void @dummy(ptr %call1)
35  ;; Attribute hot converted to __hot_cold_t hot value.
36  ; HOTCOLD: @_Znwm12__hot_cold_t(i64 10, i8 [[HOT]])
37  %call2 = call ptr @_Znwm(i64 10) #2
38  call void @dummy(ptr %call2)
39  ret void
40}
41
42;; Check that operator new(unsigned long, std::align_val_t) converted to
43;; operator new(unsigned long, std::align_val_t, __hot_cold_t) with a hot or
44;; cold attribute.
45; HOTCOLD-LABEL: @new_align()
46define void @new_align() {
47  ;; Attribute cold converted to __hot_cold_t cold value.
48  ; HOTCOLD: @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[COLD]])
49  %call = call ptr @_ZnwmSt11align_val_t(i64 10, i64 8) #0
50  call void @dummy(ptr %call)
51  ;; Attribute notcold has no effect.
52  ; HOTCOLD: @_ZnwmSt11align_val_t(i64 10, i64 8)
53  %call1 = call ptr @_ZnwmSt11align_val_t(i64 10, i64 8) #1
54  call void @dummy(ptr %call1)
55  ;; Attribute hot converted to __hot_cold_t hot value.
56  ; HOTCOLD: @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[HOT]])
57  %call2 = call ptr @_ZnwmSt11align_val_t(i64 10, i64 8) #2
58  call void @dummy(ptr %call2)
59  ret void
60}
61
62;; Check that operator new(unsigned long, const std::nothrow_t&) converted to
63;; operator new(unsigned long, const std::nothrow_t&, __hot_cold_t) with a hot or
64;; cold attribute.
65; HOTCOLD-LABEL: @new_nothrow()
66define void @new_nothrow() {
67  %nt = alloca i8
68  ;; Attribute cold converted to __hot_cold_t cold value.
69  ; HOTCOLD: @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[COLD]])
70  %call = call ptr @_ZnwmRKSt9nothrow_t(i64 10, ptr %nt) #0
71  call void @dummy(ptr %call)
72  ;; Attribute notcold has no effect.
73  ; HOTCOLD: @_ZnwmRKSt9nothrow_t(i64 10, ptr nonnull %nt)
74  %call1 = call ptr @_ZnwmRKSt9nothrow_t(i64 10, ptr %nt) #1
75  call void @dummy(ptr %call1)
76  ;; Attribute hot converted to __hot_cold_t hot value.
77  ; HOTCOLD: @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[HOT]])
78  %call2 = call ptr @_ZnwmRKSt9nothrow_t(i64 10, ptr %nt) #2
79  call void @dummy(ptr %call2)
80  ret void
81}
82
83;; Check that operator new(unsigned long, std::align_val_t, const std::nothrow_t&)
84;; converted to
85;; operator new(unsigned long, std::align_val_t, const std::nothrow_t&, __hot_cold_t)
86;; with a hot or cold attribute.
87; HOTCOLD-LABEL: @new_align_nothrow()
88define void @new_align_nothrow() {
89  %nt = alloca i8
90  ;; Attribute cold converted to __hot_cold_t cold value.
91  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[COLD]])
92  %call = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #0
93  call void @dummy(ptr %call)
94  ;; Attribute notcold has no effect.
95  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr nonnull %nt)
96  %call1 = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #1
97  call void @dummy(ptr %call1)
98  ;; Attribute hot converted to __hot_cold_t hot value.
99  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[HOT]])
100  %call2 = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #2
101  call void @dummy(ptr %call2)
102  ret void
103}
104
105;; Check that operator new[](unsigned long) converted to
106;; operator new[](unsigned long, __hot_cold_t) with a hot or cold attribute.
107; HOTCOLD-LABEL: @array_new()
108define void @array_new() {
109  ;; Attribute cold converted to __hot_cold_t cold value.
110  ; HOTCOLD: @_Znam12__hot_cold_t(i64 10, i8 [[COLD]])
111  %call = call ptr @_Znam(i64 10) #0
112  call void @dummy(ptr %call)
113  ;; Attribute notcold has no effect.
114  ; HOTCOLD: @_Znam(i64 10)
115  %call1 = call ptr @_Znam(i64 10) #1
116  call void @dummy(ptr %call1)
117  ;; Attribute hot converted to __hot_cold_t hot value.
118  ; HOTCOLD: @_Znam12__hot_cold_t(i64 10, i8 [[HOT]])
119  %call2 = call ptr @_Znam(i64 10) #2
120  call void @dummy(ptr %call2)
121  ret void
122}
123
124;; Check that operator new[](unsigned long, std::align_val_t) converted to
125;; operator new[](unsigned long, std::align_val_t, __hot_cold_t) with a hot or
126;; cold attribute.
127; HOTCOLD-LABEL: @array_new_align()
128define void @array_new_align() {
129  ;; Attribute cold converted to __hot_cold_t cold value.
130  ; HOTCOLD: @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[COLD]])
131  %call = call ptr @_ZnamSt11align_val_t(i64 10, i64 8) #0
132  call void @dummy(ptr %call)
133  ;; Attribute notcold has no effect.
134  ; HOTCOLD: @_ZnamSt11align_val_t(i64 10, i64 8)
135  %call1 = call ptr @_ZnamSt11align_val_t(i64 10, i64 8) #1
136  call void @dummy(ptr %call1)
137  ;; Attribute hot converted to __hot_cold_t hot value.
138  ; HOTCOLD: @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[HOT]])
139  %call2 = call ptr @_ZnamSt11align_val_t(i64 10, i64 8) #2
140  call void @dummy(ptr %call2)
141  ret void
142}
143
144;; Check that operator new[](unsigned long, const std::nothrow_t&) converted to
145;; operator new[](unsigned long, const std::nothrow_t&, __hot_cold_t) with a hot or
146;; cold attribute.
147; HOTCOLD-LABEL: @array_new_nothrow()
148define void @array_new_nothrow() {
149  %nt = alloca i8
150  ;; Attribute cold converted to __hot_cold_t cold value.
151  ; HOTCOLD: @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[COLD]])
152  %call = call ptr @_ZnamRKSt9nothrow_t(i64 10, ptr %nt) #0
153  call void @dummy(ptr %call)
154  ;; Attribute notcold has no effect.
155  ; HOTCOLD: @_ZnamRKSt9nothrow_t(i64 10, ptr nonnull %nt)
156  %call1 = call ptr @_ZnamRKSt9nothrow_t(i64 10, ptr %nt) #1
157  call void @dummy(ptr %call1)
158  ;; Attribute hot converted to __hot_cold_t hot value.
159  ; HOTCOLD: @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[HOT]])
160  %call2 = call ptr @_ZnamRKSt9nothrow_t(i64 10, ptr %nt) #2
161  call void @dummy(ptr %call2)
162  ret void
163}
164
165;; Check that operator new[](unsigned long, std::align_val_t, const std::nothrow_t&)
166;; converted to
167;; operator new[](unsigned long, std::align_val_t, const std::nothrow_t&, __hot_cold_t)
168;; with a hot or cold attribute.
169; HOTCOLD-LABEL: @array_new_align_nothrow()
170define void @array_new_align_nothrow() {
171  %nt = alloca i8
172  ;; Attribute cold converted to __hot_cold_t cold value.
173  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[COLD]])
174  %call = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #0
175  call void @dummy(ptr %call)
176  ;; Attribute notcold has no effect.
177  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr nonnull %nt)
178  %call1 = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #1
179  call void @dummy(ptr %call1)
180  ;; Attribute hot converted to __hot_cold_t hot value.
181  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[HOT]])
182  %call2 = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64 10, i64 8, ptr %nt) #2
183  call void @dummy(ptr %call2)
184  ret void
185}
186
187;; Check that operator new(unsigned long, __hot_cold_t)
188;; optionally has its hint updated.
189; HOTCOLD-LABEL: @new_hot_cold()
190define void @new_hot_cold() {
191  ;; Attribute cold converted to __hot_cold_t cold value.
192  ; HOTCOLD: @_Znwm12__hot_cold_t(i64 10, i8 [[PREVHINTCOLD]])
193  %call = call ptr @_Znwm12__hot_cold_t(i64 10, i8 7) #0
194  call void @dummy(ptr %call)
195  ;; Attribute notcold converted to __hot_cold_t notcold value.
196  ; HOTCOLD: @_Znwm12__hot_cold_t(i64 10, i8 [[PREVHINTNOTCOLD]])
197  %call1 = call ptr @_Znwm12__hot_cold_t(i64 10, i8 7) #1
198  call void @dummy(ptr %call1)
199  ;; Attribute hot converted to __hot_cold_t hot value.
200  ; HOTCOLD: @_Znwm12__hot_cold_t(i64 10, i8 [[PREVHINTHOT]])
201  %call2 = call ptr @_Znwm12__hot_cold_t(i64 10, i8 7) #2
202  call void @dummy(ptr %call2)
203  ret void
204}
205
206;; Check that operator new(unsigned long, std::align_val_t, __hot_cold_t)
207;; optionally has its hint updated.
208; HOTCOLD-LABEL: @new_align_hot_cold()
209define void @new_align_hot_cold() {
210  ;; Attribute cold converted to __hot_cold_t cold value.
211  ; HOTCOLD: @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTCOLD]])
212  %call = call ptr @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #0
213  call void @dummy(ptr %call)
214  ;; Attribute notcold converted to __hot_cold_t notcold value.
215  ; HOTCOLD: @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTNOTCOLD]])
216  %call1 = call ptr @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #1
217  call void @dummy(ptr %call1)
218  ;; Attribute hot converted to __hot_cold_t hot value.
219  ; HOTCOLD: @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTHOT]])
220  %call2 = call ptr @_ZnwmSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #2
221  call void @dummy(ptr %call2)
222  ret void
223}
224
225;; Check that operator new(unsigned long, const std::nothrow_t&, __hot_cold_t)
226;; optionally has its hint updated.
227; HOTCOLD-LABEL: @new_nothrow_hot_cold()
228define void @new_nothrow_hot_cold() {
229  %nt = alloca i8
230  ;; Attribute cold converted to __hot_cold_t cold value.
231  ; HOTCOLD: @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTCOLD]])
232  %call = call ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #0
233  call void @dummy(ptr %call)
234  ;; Attribute notcold converted to __hot_cold_t notcold value.
235  ; HOTCOLD: @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTNOTCOLD]])
236  %call1 = call ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #1
237  call void @dummy(ptr %call1)
238  ;; Attribute hot converted to __hot_cold_t hot value.
239  ; HOTCOLD: @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTHOT]])
240  %call2 = call ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #2
241  call void @dummy(ptr %call2)
242  ret void
243}
244
245;; Check that operator new(unsigned long, std::align_val_t, const std::nothrow_t&, __hot_cold_t)
246;; optionally has its hint updated.
247; HOTCOLD-LABEL: @new_align_nothrow_hot_cold()
248define void @new_align_nothrow_hot_cold() {
249  %nt = alloca i8
250  ;; Attribute cold converted to __hot_cold_t cold value.
251  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTCOLD]])
252  %call = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #0
253  call void @dummy(ptr %call)
254  ;; Attribute notcold converted to __hot_cold_t notcold value.
255  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTNOTCOLD]])
256  %call1 = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #1
257  call void @dummy(ptr %call1)
258  ;; Attribute hot converted to __hot_cold_t hot value.
259  ; HOTCOLD: @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTHOT]])
260  %call2 = call ptr @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #2
261  call void @dummy(ptr %call2)
262  ret void
263}
264
265;; Check that operator new[](unsigned long, __hot_cold_t)
266;; optionally has its hint updated.
267; HOTCOLD-LABEL: @array_new_hot_cold()
268define void @array_new_hot_cold() {
269  ;; Attribute cold converted to __hot_cold_t cold value.
270  ; HOTCOLD: @_Znam12__hot_cold_t(i64 10, i8 [[PREVHINTCOLD]])
271  %call = call ptr @_Znam12__hot_cold_t(i64 10, i8 7) #0
272  call void @dummy(ptr %call)
273  ;; Attribute notcold converted to __hot_cold_t notcold value.
274  ; HOTCOLD: @_Znam12__hot_cold_t(i64 10, i8 [[PREVHINTNOTCOLD]])
275  %call1 = call ptr @_Znam12__hot_cold_t(i64 10, i8 7) #1
276  call void @dummy(ptr %call1)
277  ;; Attribute hot converted to __hot_cold_t hot value.
278  ; HOTCOLD: @_Znam12__hot_cold_t(i64 10, i8 [[PREVHINTHOT]])
279  %call2 = call ptr @_Znam12__hot_cold_t(i64 10, i8 7) #2
280  call void @dummy(ptr %call2)
281  ret void
282}
283
284;; Check that operator new[](unsigned long, std::align_val_t, __hot_cold_t)
285;; optionally has its hint updated.
286; HOTCOLD-LABEL: @array_new_align_hot_cold()
287define void @array_new_align_hot_cold() {
288  ;; Attribute cold converted to __hot_cold_t cold value.
289  ; HOTCOLD: @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTCOLD]])
290  %call = call ptr @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #0
291  call void @dummy(ptr %call)
292  ;; Attribute notcold converted to __hot_cold_t notcold value.
293  ; HOTCOLD: @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTNOTCOLD]])
294  %call1 = call ptr @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #1
295  call void @dummy(ptr %call1)
296  ;; Attribute hot converted to __hot_cold_t hot value.
297  ; HOTCOLD: @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 [[PREVHINTHOT]])
298  %call2 = call ptr @_ZnamSt11align_val_t12__hot_cold_t(i64 10, i64 8, i8 7) #2
299  call void @dummy(ptr %call2)
300  ret void
301}
302
303;; Check that operator new[](unsigned long, const std::nothrow_t&, __hot_cold_t)
304;; optionally has its hint updated.
305; HOTCOLD-LABEL: @array_new_nothrow_hot_cold()
306define void @array_new_nothrow_hot_cold() {
307  %nt = alloca i8
308  ;; Attribute cold converted to __hot_cold_t cold value.
309  ; HOTCOLD: @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTCOLD]])
310  %call = call ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #0
311  call void @dummy(ptr %call)
312  ;; Attribute notcold converted to __hot_cold_t notcold value.
313  ; HOTCOLD: @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTNOTCOLD]])
314  %call1 = call ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #1
315  call void @dummy(ptr %call1)
316  ;; Attribute hot converted to __hot_cold_t hot value.
317  ; HOTCOLD: @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr nonnull %nt, i8 [[PREVHINTHOT]])
318  %call2 = call ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 10, ptr %nt, i8 7) #2
319  call void @dummy(ptr %call2)
320  ret void
321}
322
323;; Check that operator new[](unsigned long, std::align_val_t, const std::nothrow_t&, __hot_cold_t)
324;; optionally has its hint updated.
325; HOTCOLD-LABEL: @array_new_align_nothrow_hot_cold()
326define void @array_new_align_nothrow_hot_cold() {
327  %nt = alloca i8
328  ;; Attribute cold converted to __hot_cold_t cold value.
329  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTCOLD]])
330  %call = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #0
331  call void @dummy(ptr %call)
332  ;; Attribute notcold converted to __hot_cold_t notcold value.
333  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTNOTCOLD]])
334  %call1 = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #1
335  call void @dummy(ptr %call1)
336  ;; Attribute hot converted to __hot_cold_t hot value.
337  ; HOTCOLD: @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr nonnull %nt, i8 [[PREVHINTHOT]])
338  %call2 = call ptr @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64 10, i64 8, ptr %nt, i8 7) #2
339  call void @dummy(ptr %call2)
340  ret void
341}
342
343;; Check that operator __size_returning_new(unsigned long) converted to
344;; __size_returning_new(unsigned long, __hot_cold_t) with a hot or cold attribute.
345; HOTCOLD-LABEL: @size_returning_test()
346define void @size_returning_test() {
347  ;; Attribute cold converted to __hot_cold_t cold value.
348  ; HOTCOLD: @__size_returning_new_hot_cold(i64 10, i8 [[COLD]])
349  %call = call {ptr, i64} @__size_returning_new(i64 10) #3
350  %p  = extractvalue {ptr, i64} %call, 0
351  call void @dummy(ptr %p)
352  ;; Attribute notcold has no effect.
353  ; HOTCOLD: @__size_returning_new(i64 10)
354  %call1 = call {ptr, i64} @__size_returning_new(i64 10) #4
355  %p1  = extractvalue {ptr, i64} %call1, 0
356  call void @dummy(ptr %p1)
357  ;; Attribute hot converted to __hot_cold_t hot value.
358  ; HOTCOLD: @__size_returning_new_hot_cold(i64 10, i8 [[HOT]])
359  %call2 = call {ptr, i64} @__size_returning_new(i64 10) #5
360  %p2  = extractvalue {ptr, i64} %call2, 0
361  call void @dummy(ptr %p2)
362  ret void
363}
364
365;; Check that operator __size_returning_new_aligned(unsigned long, std::align_val_t) converted to
366;; __size_returning_new_aligned(unsigned long, std::align_val_t, __hot_cold_t) with a hot or cold attribute.
367; HOTCOLD-LABEL: @size_returning_aligned_test()
368define void @size_returning_aligned_test() {
369  ;; Attribute cold converted to __hot_cold_t cold value.
370  ; HOTCOLD: @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 [[COLD]])
371  %call = call {ptr, i64} @__size_returning_new_aligned(i64 10, i64 8) #3
372  %p  = extractvalue {ptr, i64} %call, 0
373  call void @dummy(ptr %p)
374  ;; Attribute notcold has no effect.
375  ; HOTCOLD: @__size_returning_new_aligned(i64 10, i64 8)
376  %call1 = call {ptr, i64} @__size_returning_new_aligned(i64 10, i64 8) #4
377  %p1  = extractvalue {ptr, i64} %call1, 0
378  call void @dummy(ptr %p1)
379  ;; Attribute hot converted to __hot_cold_t hot value.
380  ; HOTCOLD: @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 [[HOT]])
381  %call2 = call {ptr, i64} @__size_returning_new_aligned(i64 10, i64 8) #5
382  %p2  = extractvalue {ptr, i64} %call2, 0
383  call void @dummy(ptr %p2)
384  ret void
385}
386
387;; Check that __size_returning_new_hot_cold(unsigned long, __hot_cold_t)
388;; optionally has its hint updated.
389; HOTCOLD-LABEL: @size_returning_update_test()
390define void @size_returning_update_test() {
391  ;; Attribute cold converted to __hot_cold_t cold value.
392  ; HOTCOLD: @__size_returning_new_hot_cold(i64 10, i8 [[PREVHINTCOLD]])
393  %call = call {ptr, i64} @__size_returning_new_hot_cold(i64 10, i8 7) #3
394  %p  = extractvalue {ptr, i64} %call, 0
395  call void @dummy(ptr %p)
396  ;; Attribute notcold converted to __hot_cold_t notcold value.
397  ; HOTCOLD: @__size_returning_new_hot_cold(i64 10, i8 [[PREVHINTNOTCOLD]])
398  %call1 = call {ptr, i64} @__size_returning_new_hot_cold(i64 10, i8 7) #4
399  %p1 = extractvalue {ptr, i64} %call1, 0
400  call void @dummy(ptr %p1)
401  ;; Attribute hot converted to __hot_cold_t hot value.
402  ; HOTCOLD: @__size_returning_new_hot_cold(i64 10, i8 [[PREVHINTHOT]])
403  %call2 = call {ptr, i64} @__size_returning_new_hot_cold(i64 10, i8 7) #5
404  %p2 = extractvalue {ptr, i64} %call2, 0
405  call void @dummy(ptr %p2)
406  ret void
407}
408
409;; Check that __size_returning_new_aligned_hot_cold(unsigned long, __hot_cold_t)
410;; optionally has its hint updated.
411; HOTCOLD-LABEL: @size_returning_aligned_update_test()
412define void @size_returning_aligned_update_test() {
413  ;; Attribute cold converted to __hot_cold_t cold value.
414  ; HOTCOLD: @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 [[PREVHINTCOLD]])
415  %call = call {ptr, i64} @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 7) #3
416  %p  = extractvalue {ptr, i64} %call, 0
417  call void @dummy(ptr %p)
418  ;; Attribute notcold converted to __hot_cold_t notcold value.
419  ; HOTCOLD: @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 [[PREVHINTNOTCOLD]])
420  %call1 = call {ptr, i64} @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 7) #4
421  %p1 = extractvalue {ptr, i64} %call1, 0
422  call void @dummy(ptr %p1)
423  ;; Attribute hot converted to __hot_cold_t hot value.
424  ; HOTCOLD: @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 [[PREVHINTHOT]])
425  %call2 = call {ptr, i64} @__size_returning_new_aligned_hot_cold(i64 10, i64 8, i8 7) #5
426  %p2 = extractvalue {ptr, i64} %call2, 0
427  call void @dummy(ptr %p2)
428  ret void
429}
430
431;; So that instcombine doesn't optimize out the call.
432declare void @dummy(ptr)
433
434declare ptr @_Znwm(i64)
435declare ptr @_ZnwmSt11align_val_t(i64, i64)
436declare ptr @_ZnwmRKSt9nothrow_t(i64, ptr)
437declare ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, ptr)
438declare ptr @_Znam(i64)
439declare ptr @_ZnamSt11align_val_t(i64, i64)
440declare ptr @_ZnamRKSt9nothrow_t(i64, ptr)
441declare ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64, i64, ptr)
442declare ptr @_Znwm12__hot_cold_t(i64, i8)
443declare ptr @_ZnwmSt11align_val_t12__hot_cold_t(i64, i64, i8)
444declare ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64, ptr, i8)
445declare ptr @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, ptr, i8)
446declare ptr @_Znam12__hot_cold_t(i64, i8)
447declare ptr @_ZnamSt11align_val_t12__hot_cold_t(i64, i64, i8)
448declare ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64, ptr, i8)
449declare ptr @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, ptr, i8)
450
451
452declare {ptr, i64} @__size_returning_new(i64)
453declare {ptr, i64} @__size_returning_new_hot_cold(i64, i8)
454declare {ptr, i64} @__size_returning_new_aligned(i64, i64)
455declare {ptr, i64} @__size_returning_new_aligned_hot_cold(i64, i64, i8)
456
457attributes #0 = { builtin allocsize(0) "memprof"="cold" }
458attributes #1 = { builtin allocsize(0) "memprof"="notcold" }
459attributes #2 = { builtin allocsize(0) "memprof"="hot" }
460
461;; Use separate attributes for __size_returning_new variants since they are not
462;; treated as builtins.
463attributes #3 = { "memprof" = "cold" }
464attributes #4 = { "memprof" = "notcold" }
465attributes #5 = { "memprof" = "hot" }
466