1d7d0e740STeresa Johnson;; Tests memprof when contains loop unroll of allocation, where the unrolled 2d7d0e740STeresa Johnson;; allocations have the same context but different allocation types. 31e7d5871Slifengxiang1025 41e7d5871Slifengxiang1025;; Avoid failures on big-endian systems that can't read the profile properly 51e7d5871Slifengxiang1025; REQUIRES: x86_64-linux 61e7d5871Slifengxiang1025 71e7d5871Slifengxiang1025;; TODO: Use text profile inputs once that is available for memprof. 81e7d5871Slifengxiang1025;; # To update the Inputs below, run Inputs/update_memprof_inputs.sh. 91e7d5871Slifengxiang1025;; # To generate below LLVM IR for use in matching. 101e7d5871Slifengxiang1025;; $ clang++ -gmlt -fdebug-info-for-profiling -S %S/Inputs/memprof_loop_unroll_b.cc -emit-llvm 111e7d5871Slifengxiang1025 121e7d5871Slifengxiang1025; RUN: llvm-profdata merge %S/Inputs/memprof_loop_unroll.memprofraw --profiled-binary %S/Inputs/memprof_loop_unroll.exe -o %t.memprofdata 13*ae8b5608STeresa Johnson;; Set the minimum lifetime threshold to 0 to ensure that one context is 14*ae8b5608STeresa Johnson;; considered cold (the other will be notcold). 15*ae8b5608STeresa Johnson; RUN: opt < %s -passes='memprof-use<profile-filename=%t.memprofdata>' -S -memprof-report-hinted-sizes -memprof-ave-lifetime-cold-threshold=0 2>&1 | FileCheck %s 161e7d5871Slifengxiang1025 17d7d0e740STeresa Johnson;; Conservatively annotate as not cold. We get two messages as there are two 18d7d0e740STeresa Johnson;; unrolled copies of the allocation. 19d7d0e740STeresa Johnson; CHECK: MemProf hinting: Total size for full allocation context hash {{.*}} and indistinguishable alloc type notcold: 4 20d7d0e740STeresa Johnson; CHECK: MemProf hinting: Total size for full allocation context hash {{.*}} and indistinguishable alloc type notcold: 4 211e7d5871Slifengxiang1025; CHECK: call {{.*}} @_Znam{{.*}} #[[ATTR:[0-9]+]] 221e7d5871Slifengxiang1025; CHECK: attributes #[[ATTR]] = { builtin allocsize(0) "memprof"="notcold" } 231e7d5871Slifengxiang1025; CHECK-NOT: stackIds: () 241e7d5871Slifengxiang1025 251e7d5871Slifengxiang1025; ModuleID = 'memprof_loop_unroll_b.cc' 261e7d5871Slifengxiang1025source_filename = "memprof_loop_unroll_b.cc" 271e7d5871Slifengxiang1025target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 281e7d5871Slifengxiang1025target triple = "x86_64-unknown-linux-gnu" 291e7d5871Slifengxiang1025 301e7d5871Slifengxiang1025@a = external global [2 x ptr], align 16 311e7d5871Slifengxiang1025 321e7d5871Slifengxiang1025; Function Attrs: mustprogress noinline optnone uwtable 331e7d5871Slifengxiang1025define dso_local void @_Z3foov() #0 !dbg !10 { 341e7d5871Slifengxiang1025entry: 351e7d5871Slifengxiang1025 %i = alloca i32, align 4 361e7d5871Slifengxiang1025 store i32 0, ptr %i, align 4, !dbg !13 371e7d5871Slifengxiang1025 br label %for.cond, !dbg !14 381e7d5871Slifengxiang1025 391e7d5871Slifengxiang1025for.cond: ; preds = %for.inc, %entry 401e7d5871Slifengxiang1025 %0 = load i32, ptr %i, align 4, !dbg !15 411e7d5871Slifengxiang1025 %cmp = icmp slt i32 %0, 2, !dbg !17 421e7d5871Slifengxiang1025 br i1 %cmp, label %for.body, label %for.end, !dbg !18 431e7d5871Slifengxiang1025 441e7d5871Slifengxiang1025for.body: ; preds = %for.cond 451e7d5871Slifengxiang1025 %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 4) #2, !dbg !19 461e7d5871Slifengxiang1025 %1 = load i32, ptr %i, align 4, !dbg !20 471e7d5871Slifengxiang1025 %idxprom = sext i32 %1 to i64, !dbg !21 481e7d5871Slifengxiang1025 %arrayidx = getelementptr inbounds [2 x ptr], ptr @a, i64 0, i64 %idxprom, !dbg !21 491e7d5871Slifengxiang1025 store ptr %call, ptr %arrayidx, align 8, !dbg !22 501e7d5871Slifengxiang1025 br label %for.inc, !dbg !23 511e7d5871Slifengxiang1025 521e7d5871Slifengxiang1025for.inc: ; preds = %for.body 531e7d5871Slifengxiang1025 %2 = load i32, ptr %i, align 4, !dbg !24 541e7d5871Slifengxiang1025 %inc = add nsw i32 %2, 1, !dbg !24 551e7d5871Slifengxiang1025 store i32 %inc, ptr %i, align 4, !dbg !24 561e7d5871Slifengxiang1025 br label %for.cond, !dbg !26, !llvm.loop !27 571e7d5871Slifengxiang1025 581e7d5871Slifengxiang1025for.end: ; preds = %for.cond 591e7d5871Slifengxiang1025 ret void, !dbg !30 601e7d5871Slifengxiang1025} 611e7d5871Slifengxiang1025 621e7d5871Slifengxiang1025; Function Attrs: nobuiltin allocsize(0) 631e7d5871Slifengxiang1025declare noundef nonnull ptr @_Znam(i64 noundef) #1 641e7d5871Slifengxiang1025 651e7d5871Slifengxiang1025attributes #0 = { mustprogress noinline optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 661e7d5871Slifengxiang1025attributes #1 = { nobuiltin allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 671e7d5871Slifengxiang1025attributes #2 = { builtin allocsize(0) } 681e7d5871Slifengxiang1025 691e7d5871Slifengxiang1025!llvm.dbg.cu = !{!0} 701e7d5871Slifengxiang1025!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} 711e7d5871Slifengxiang1025!llvm.ident = !{!9} 721e7d5871Slifengxiang1025 731e7d5871Slifengxiang1025!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) 741e7d5871Slifengxiang1025!1 = !DIFile(filename: "memprof_loop_unroll_b.cc", directory: "/", checksumkind: CSK_MD5, checksum: "00276e590d606451dc54f3ff5f4bba25") 751e7d5871Slifengxiang1025!2 = !{i32 7, !"Dwarf Version", i32 5} 761e7d5871Slifengxiang1025!3 = !{i32 2, !"Debug Info Version", i32 3} 771e7d5871Slifengxiang1025!4 = !{i32 1, !"wchar_size", i32 4} 781e7d5871Slifengxiang1025!5 = !{i32 8, !"PIC Level", i32 2} 791e7d5871Slifengxiang1025!6 = !{i32 7, !"PIE Level", i32 2} 801e7d5871Slifengxiang1025!7 = !{i32 7, !"uwtable", i32 2} 811e7d5871Slifengxiang1025!8 = !{i32 7, !"frame-pointer", i32 2} 821e7d5871Slifengxiang1025!9 = !{!"clang version 18.0.0"} 831e7d5871Slifengxiang1025!10 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0) 841e7d5871Slifengxiang1025!11 = !DISubroutineType(types: !12) 851e7d5871Slifengxiang1025!12 = !{} 861e7d5871Slifengxiang1025!13 = !DILocation(line: 5, column: 14, scope: !10) 871e7d5871Slifengxiang1025!14 = !DILocation(line: 5, column: 10, scope: !10) 881e7d5871Slifengxiang1025!15 = !DILocation(line: 5, column: 21, scope: !16) 891e7d5871Slifengxiang1025!16 = !DILexicalBlockFile(scope: !10, file: !1, discriminator: 2) 901e7d5871Slifengxiang1025!17 = !DILocation(line: 5, column: 23, scope: !16) 911e7d5871Slifengxiang1025!18 = !DILocation(line: 5, column: 5, scope: !16) 921e7d5871Slifengxiang1025!19 = !DILocation(line: 6, column: 16, scope: !10) 931e7d5871Slifengxiang1025!20 = !DILocation(line: 6, column: 11, scope: !10) 941e7d5871Slifengxiang1025!21 = !DILocation(line: 6, column: 9, scope: !10) 951e7d5871Slifengxiang1025!22 = !DILocation(line: 6, column: 14, scope: !10) 961e7d5871Slifengxiang1025!23 = !DILocation(line: 7, column: 5, scope: !10) 971e7d5871Slifengxiang1025!24 = !DILocation(line: 5, column: 28, scope: !25) 981e7d5871Slifengxiang1025!25 = !DILexicalBlockFile(scope: !10, file: !1, discriminator: 4) 991e7d5871Slifengxiang1025!26 = !DILocation(line: 5, column: 5, scope: !25) 1001e7d5871Slifengxiang1025!27 = distinct !{!27, !28, !23, !29} 1011e7d5871Slifengxiang1025!28 = !DILocation(line: 5, column: 5, scope: !10) 1021e7d5871Slifengxiang1025!29 = !{!"llvm.loop.mustprogress"} 1031e7d5871Slifengxiang1025!30 = !DILocation(line: 8, column: 1, scope: !10) 104