Skip to content

Commit cec6665

Browse files
[MemProf] Optionally update hints on existing hot/cold new calls (#91047)
If directed by an option, update hints on calls to new that already provide a hot/cold hint.
1 parent b52160d commit cec6665

File tree

2 files changed

+288
-25
lines changed

2 files changed

+288
-25
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 115 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static cl::opt<bool>
5252
static cl::opt<bool>
5353
OptimizeHotColdNew("optimize-hot-cold-new", cl::Hidden, cl::init(false),
5454
cl::desc("Enable hot/cold operator new library calls"));
55+
static cl::opt<bool> OptimizeExistingHotColdNew(
56+
"optimize-existing-hot-cold-new", cl::Hidden, cl::init(false),
57+
cl::desc(
58+
"Enable optimization of existing hot/cold operator new library calls"));
5559

5660
namespace {
5761

@@ -81,6 +85,10 @@ struct HotColdHintParser : public cl::parser<unsigned> {
8185
static cl::opt<unsigned, false, HotColdHintParser> ColdNewHintValue(
8286
"cold-new-hint-value", cl::Hidden, cl::init(1),
8387
cl::desc("Value to pass to hot/cold operator new for cold allocation"));
88+
static cl::opt<unsigned, false, HotColdHintParser>
89+
NotColdNewHintValue("notcold-new-hint-value", cl::Hidden, cl::init(128),
90+
cl::desc("Value to pass to hot/cold operator new for "
91+
"notcold (warm) allocation"));
8492
static cl::opt<unsigned, false, HotColdHintParser> HotNewHintValue(
8593
"hot-new-hint-value", cl::Hidden, cl::init(254),
8694
cl::desc("Value to pass to hot/cold operator new for hot allocation"));
@@ -1722,45 +1730,122 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
17221730
uint8_t HotCold;
17231731
if (CI->getAttributes().getFnAttr("memprof").getValueAsString() == "cold")
17241732
HotCold = ColdNewHintValue;
1733+
else if (CI->getAttributes().getFnAttr("memprof").getValueAsString() ==
1734+
"notcold")
1735+
HotCold = NotColdNewHintValue;
17251736
else if (CI->getAttributes().getFnAttr("memprof").getValueAsString() == "hot")
17261737
HotCold = HotNewHintValue;
17271738
else
17281739
return nullptr;
17291740

1741+
// For calls that already pass a hot/cold hint, only update the hint if
1742+
// directed by OptimizeExistingHotColdNew. For other calls to new, add a hint
1743+
// if cold or hot, and leave as-is for default handling if "notcold" aka warm.
1744+
// Note that in cases where we decide it is "notcold", it might be slightly
1745+
// better to replace the hinted call with a non hinted call, to avoid the
1746+
// extra paramter and the if condition check of the hint value in the
1747+
// allocator. This can be considered in the future.
17301748
switch (Func) {
1749+
case LibFunc_Znwm12__hot_cold_t:
1750+
if (OptimizeExistingHotColdNew)
1751+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1752+
LibFunc_Znwm12__hot_cold_t, HotCold);
1753+
break;
17311754
case LibFunc_Znwm:
1732-
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1733-
LibFunc_Znwm12__hot_cold_t, HotCold);
1755+
if (HotCold != NotColdNewHintValue)
1756+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1757+
LibFunc_Znwm12__hot_cold_t, HotCold);
1758+
break;
1759+
case LibFunc_Znam12__hot_cold_t:
1760+
if (OptimizeExistingHotColdNew)
1761+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1762+
LibFunc_Znam12__hot_cold_t, HotCold);
1763+
break;
17341764
case LibFunc_Znam:
1735-
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1736-
LibFunc_Znam12__hot_cold_t, HotCold);
1765+
if (HotCold != NotColdNewHintValue)
1766+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1767+
LibFunc_Znam12__hot_cold_t, HotCold);
1768+
break;
1769+
case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1770+
if (OptimizeExistingHotColdNew)
1771+
return emitHotColdNewNoThrow(
1772+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1773+
LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1774+
break;
17371775
case LibFunc_ZnwmRKSt9nothrow_t:
1738-
return emitHotColdNewNoThrow(CI->getArgOperand(0), CI->getArgOperand(1), B,
1739-
TLI, LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,
1740-
HotCold);
1776+
if (HotCold != NotColdNewHintValue)
1777+
return emitHotColdNewNoThrow(
1778+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1779+
LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1780+
break;
1781+
case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1782+
if (OptimizeExistingHotColdNew)
1783+
return emitHotColdNewNoThrow(
1784+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1785+
LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1786+
break;
17411787
case LibFunc_ZnamRKSt9nothrow_t:
1742-
return emitHotColdNewNoThrow(CI->getArgOperand(0), CI->getArgOperand(1), B,
1743-
TLI, LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,
1744-
HotCold);
1788+
if (HotCold != NotColdNewHintValue)
1789+
return emitHotColdNewNoThrow(
1790+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1791+
LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1792+
break;
1793+
case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1794+
if (OptimizeExistingHotColdNew)
1795+
return emitHotColdNewAligned(
1796+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1797+
LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1798+
break;
17451799
case LibFunc_ZnwmSt11align_val_t:
1746-
return emitHotColdNewAligned(CI->getArgOperand(0), CI->getArgOperand(1), B,
1747-
TLI, LibFunc_ZnwmSt11align_val_t12__hot_cold_t,
1748-
HotCold);
1800+
if (HotCold != NotColdNewHintValue)
1801+
return emitHotColdNewAligned(
1802+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1803+
LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1804+
break;
1805+
case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1806+
if (OptimizeExistingHotColdNew)
1807+
return emitHotColdNewAligned(
1808+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1809+
LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1810+
break;
17491811
case LibFunc_ZnamSt11align_val_t:
1750-
return emitHotColdNewAligned(CI->getArgOperand(0), CI->getArgOperand(1), B,
1751-
TLI, LibFunc_ZnamSt11align_val_t12__hot_cold_t,
1752-
HotCold);
1812+
if (HotCold != NotColdNewHintValue)
1813+
return emitHotColdNewAligned(
1814+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1815+
LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1816+
break;
1817+
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1818+
if (OptimizeExistingHotColdNew)
1819+
return emitHotColdNewAlignedNoThrow(
1820+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1821+
TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1822+
HotCold);
1823+
break;
17531824
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1754-
return emitHotColdNewAlignedNoThrow(
1755-
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1756-
TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1825+
if (HotCold != NotColdNewHintValue)
1826+
return emitHotColdNewAlignedNoThrow(
1827+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1828+
TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1829+
HotCold);
1830+
break;
1831+
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1832+
if (OptimizeExistingHotColdNew)
1833+
return emitHotColdNewAlignedNoThrow(
1834+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1835+
TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1836+
HotCold);
1837+
break;
17571838
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1758-
return emitHotColdNewAlignedNoThrow(
1759-
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1760-
TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1839+
if (HotCold != NotColdNewHintValue)
1840+
return emitHotColdNewAlignedNoThrow(
1841+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1842+
TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1843+
HotCold);
1844+
break;
17611845
default:
17621846
return nullptr;
17631847
}
1848+
return nullptr;
17641849
}
17651850

17661851
//===----------------------------------------------------------------------===//
@@ -3675,6 +3760,14 @@ Value *LibCallSimplifier::optimizeStringMemoryLibCall(CallInst *CI,
36753760
case LibFunc_ZnamRKSt9nothrow_t:
36763761
case LibFunc_ZnamSt11align_val_t:
36773762
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
3763+
case LibFunc_Znwm12__hot_cold_t:
3764+
case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
3765+
case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
3766+
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
3767+
case LibFunc_Znam12__hot_cold_t:
3768+
case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
3769+
case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
3770+
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
36783771
return optimizeNew(CI, Builder, Func);
36793772
default:
36803773
break;

llvm/test/Transforms/InstCombine/simplify-libcalls-new.ll

Lines changed: 173 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
;; Test behavior of -optimize-hot-cold-new and related options.
22

33
;; Check that we don't get hot/cold new calls without enabling it explicitly.
4-
; RUN: opt < %s -passes=instcombine -S | FileCheck %s --implicit-check-not=hot_cold_t
4+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s --check-prefix=OFF
5+
; OFF-NOT: hot_cold_t
6+
; OFF-LABEL: @new_hot_cold()
57

68
;; First check with the default cold and hot hint values (255 = -2).
7-
; RUN: opt < %s -passes=instcombine -optimize-hot-cold-new -S | FileCheck %s --check-prefix=HOTCOLD -DCOLD=1 -DHOT=-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
810

911
;; Next check with the non-default cold and hot hint values (200 =-56).
10-
; 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
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
1117

1218
;; Make sure that values not in 0..255 are flagged with an error
1319
; RUN: not opt < %s -passes=instcombine -optimize-hot-cold-new -cold-new-hint-value=256 -S 2>&1 | FileCheck %s --check-prefix=ERROR
@@ -178,6 +184,162 @@ define void @array_new_align_nothrow() {
178184
ret void
179185
}
180186

187+
;; Check that operator new(unsigned long, __hot_cold_t)
188+
;; optionally has its hint updated.
189+
; HOTCOLD-LABEL: @new_hot_cold()
190+
define 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()
209+
define 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()
228+
define 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()
248+
define 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()
268+
define 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()
287+
define 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()
306+
define 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()
326+
define 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+
181343
;; So that instcombine doesn't optimize out the call.
182344
declare void @dummy(ptr)
183345

@@ -189,6 +351,14 @@ declare ptr @_Znam(i64)
189351
declare ptr @_ZnamSt11align_val_t(i64, i64)
190352
declare ptr @_ZnamRKSt9nothrow_t(i64, ptr)
191353
declare ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64, i64, ptr)
354+
declare ptr @_Znwm12__hot_cold_t(i64, i8)
355+
declare ptr @_ZnwmSt11align_val_t12__hot_cold_t(i64, i64, i8)
356+
declare ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64, ptr, i8)
357+
declare ptr @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, ptr, i8)
358+
declare ptr @_Znam12__hot_cold_t(i64, i8)
359+
declare ptr @_ZnamSt11align_val_t12__hot_cold_t(i64, i64, i8)
360+
declare ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64, ptr, i8)
361+
declare ptr @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, ptr, i8)
192362

193363
attributes #0 = { builtin allocsize(0) "memprof"="cold" }
194364
attributes #1 = { builtin allocsize(0) "memprof"="notcold" }

0 commit comments

Comments
 (0)