[llvm] [MemProf] Propagate size info used for hint reporting to duplicates (PR #172535)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 16 10:56:24 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Teresa Johnson (teresajohnson)
<details>
<summary>Changes</summary>
When we duplicate contexts (due to clones e.g. matching different
inlined instances), we were propagating the allocation type but not the
ContextSizeInfo, which is used for -memprof-report-hinted-sizes.
This meant that we never reported hinting for any of the duplicated
contexts, which can result in conservative results as in some cases only
the duplicated contexts are able to be cloned and hinted. Note that this
change could result in overly optimistic reporting in some cases.
---
Full diff: https://github.com/llvm/llvm-project/pull/172535.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp (+4-1)
- (modified) llvm/test/Transforms/MemProfContextDisambiguation/inlined3.ll (+19-5)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 74daaae8a9952..7d98a6260eb5c 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -1507,8 +1507,11 @@ CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::duplicateContextIds(
NewContextIds.insert(++LastContextId);
OldToNewContextIds[OldId].insert(LastContextId);
assert(ContextIdToAllocationType.count(OldId));
- // The new context has the same allocation type as original.
+ // The new context has the same allocation type and size info as original.
ContextIdToAllocationType[LastContextId] = ContextIdToAllocationType[OldId];
+ auto CSI = ContextIdToContextSizeInfos.find(OldId);
+ if (CSI != ContextIdToContextSizeInfos.end())
+ ContextIdToContextSizeInfos[LastContextId] = CSI->second;
if (DotAllocContextIds.contains(OldId))
DotAllocContextIds.insert(LastContextId);
}
diff --git a/llvm/test/Transforms/MemProfContextDisambiguation/inlined3.ll b/llvm/test/Transforms/MemProfContextDisambiguation/inlined3.ll
index a2e01187108d7..ab48563e040f7 100644
--- a/llvm/test/Transforms/MemProfContextDisambiguation/inlined3.ll
+++ b/llvm/test/Transforms/MemProfContextDisambiguation/inlined3.ll
@@ -52,8 +52,9 @@
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
; RUN: -memprof-verify-ccg -memprof-verify-nodes \
; RUN: -stats -pass-remarks=memprof-context-disambiguation \
+; RUN: -memprof-report-hinted-sizes \
; RUN: %s -S 2>&1 | FileCheck %s --check-prefix=IR \
-; RUN: --check-prefix=STATS --check-prefix=REMARKS
+; RUN: --check-prefix=STATS --check-prefix=REMARKS --check-prefix=SIZES
; REMARKS: created clone _Z1Ab.memprof.1
; REMARKS: created clone _Z2XZv.memprof.1
@@ -75,6 +76,15 @@
; REMARKS: call in clone _Z1Ab marked with memprof allocation attribute cold
; REMARKS: call in clone _Z1Ab.memprof.1 marked with memprof allocation attribute notcold
+;; Cold context 234 is cloned, and only the cloned context is Cold hinted
+;; (the original doesn't full match with any IR due to inlining).
+; SIZES: NotCold full allocation context 456 with total size 400 is NotCold after cloning (context id 2)
+; SIZES: NotCold full allocation context 123 with total size 100 is NotColdCold after cloning (context id 3)
+; SIZES: Cold full allocation context 234 with total size 200 is NotColdCold after cloning (context id 4)
+; SIZES: NotCold full allocation context 123 with total size 100 is NotColdCold after cloning (context id 7)
+; SIZES: Cold full allocation context 345 with total size 300 is Cold after cloning (context id 1)
+; SIZES: Cold full allocation context 345 with total size 300 is Cold after cloning (context id 6)
+; SIZES: Cold full allocation context 234 with total size 200 is Cold after cloning (context id 5)
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@@ -136,17 +146,17 @@ attributes #7 = { builtin }
!0 = !{!1, !3}
;; Not cold context via first call to _Z1Mv in main
-!1 = !{!2, !"notcold"}
+!1 = !{!2, !"notcold", !20}
!2 = !{i64 1, i64 2, i64 8, i64 3, i64 4}
;; Cold context via second call to _Z1Mv in main
-!3 = !{!4, !"cold"}
+!3 = !{!4, !"cold", !21}
!4 = !{i64 1, i64 2, i64 8, i64 3, i64 5}
!5 = !{!6, !8}
;; Cold (trimmed) context via call to _Z3XZNv in main
-!6 = !{!7, !"cold"}
+!6 = !{!7, !"cold", !22}
!7 = !{i64 6, i64 2, i64 8}
;; Not cold (trimmed) context via call to _Z1Yv in main
-!8 = !{!9, !"notcold"}
+!8 = !{!9, !"notcold", !23}
!9 = !{i64 6, i64 7}
!10 = !{i64 1}
!11 = !{i64 6}
@@ -159,6 +169,10 @@ attributes #7 = { builtin }
!17 = !{i64 7}
!18 = !{i64 10}
!19 = !{i64 3}
+!20 = !{i64 123, i64 100}
+!21 = !{i64 234, i64 200}
+!22 = !{i64 345, i64 300}
+!23 = !{i64 456, i64 400}
; IR: define {{.*}} @_Z1Ab(i1 noundef zeroext %b)
; IR: call {{.*}} @_Znam(i64 noundef 10) #[[NOTCOLD:[0-9]+]]
``````````
</details>
https://github.com/llvm/llvm-project/pull/172535
More information about the llvm-commits
mailing list