| 1 |
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-icp-factor.prof -S -sample-profile-prioritized-inline=1 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" |
| 4 |
target triple = "x86_64-unknown-linux-gnu" |
| 5 |
|
| 6 |
@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 |
| 7 |
|
| 8 |
; Function Attrs: nounwind uwtable |
| 9 |
define dso_local i32 @bar(i32 %arg) #0 !dbg !13 { |
| 10 |
bb: |
| 11 |
%i = alloca i32, align 4 |
| 12 |
store i32 %arg, ptr %i, align 4, !tbaa !19 |
| 13 |
call void @llvm.dbg.declare(metadata ptr %i, metadata !18, metadata !DIExpression()), !dbg !23 |
| 14 |
call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !24 |
| 15 |
%i1 = load i32, ptr %i, align 4, !dbg !24, !tbaa !19 |
| 16 |
%i2 = add nsw i32 %i1, 1, !dbg !24 |
| 17 |
store i32 %i2, ptr %i, align 4, !dbg !24, !tbaa !19 |
| 18 |
%i3 = load i32, ptr %i, align 4, !dbg !25, !tbaa !19 |
| 19 |
%i4 = add nsw i32 %i3, 1, !dbg !26 |
| 20 |
ret i32 %i4, !dbg !27 |
| 21 |
} |
| 22 |
|
| 23 |
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) |
| 24 |
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 |
| 25 |
|
| 26 |
; Function Attrs: nounwind uwtable |
| 27 |
define dso_local i32 @baz(i32 %arg) #0 !dbg !28 { |
| 28 |
bb: |
| 29 |
%i = alloca i32, align 4 |
| 30 |
store i32 %arg, ptr %i, align 4, !tbaa !19 |
| 31 |
call void @llvm.dbg.declare(metadata ptr %i, metadata !30, metadata !DIExpression()), !dbg !31 |
| 32 |
call void @llvm.pseudoprobe(i64 7546896869197086323, i64 1, i32 0, i64 -1), !dbg !32 |
| 33 |
%i1 = load i32, ptr %i, align 4, !dbg !32, !tbaa !19 |
| 34 |
%i2 = add nsw i32 %i1, 10, !dbg !33 |
| 35 |
ret i32 %i2, !dbg !34 |
| 36 |
} |
| 37 |
|
| 38 |
; Function Attrs: nounwind uwtable |
| 39 |
define dso_local i32 @foo(i32 %arg, ptr %arg1) #0 !dbg !35 { |
| 40 |
bb: |
| 41 |
%i = alloca i32, align 4 |
| 42 |
%i2 = alloca ptr, align 8 |
| 43 |
store i32 %arg, ptr %i, align 4, !tbaa !19 |
| 44 |
call void @llvm.dbg.declare(metadata ptr %i, metadata !42, metadata !DIExpression()), !dbg !44 |
| 45 |
store ptr %arg1, ptr %i2, align 8, !tbaa !45 |
| 46 |
call void @llvm.dbg.declare(metadata ptr %i2, metadata !43, metadata !DIExpression()), !dbg !47 |
| 47 |
call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg !48 |
| 48 |
%i3 = load ptr, ptr %i2, align 8, !dbg !48, !tbaa !45 |
| 49 |
%i4 = load i32, ptr %i, align 4, !dbg !49, !tbaa !19 |
| 50 |
%i6 = call i32 (i32, ...) %i3(i32 %i4), !dbg !50 |
| 51 |
ret i32 %i6, !dbg !52 |
| 52 |
} |
| 53 |
|
| 54 |
; Function Attrs: nounwind uwtable |
| 55 |
define dso_local i32 @main() #0 !dbg !53 { |
| 56 |
bb: |
| 57 |
%i = alloca i32, align 4 |
| 58 |
%i1 = alloca ptr, align 8 |
| 59 |
%i2 = alloca i32, align 4 |
| 60 |
%i3 = alloca i32, align 4 |
| 61 |
store i32 0, ptr %i, align 4 |
| 62 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !62 |
| 63 |
call void @llvm.lifetime.start.p0(ptr %i1), !dbg !62 |
| 64 |
call void @llvm.dbg.declare(metadata ptr %i1, metadata !57, metadata !DIExpression()), !dbg !63 |
| 65 |
call void @llvm.lifetime.start.p0(ptr %i2), !dbg !64 |
| 66 |
call void @llvm.dbg.declare(metadata ptr %i2, metadata !59, metadata !DIExpression()), !dbg !65 |
| 67 |
store i32 0, ptr %i2, align 4, !dbg !65, !tbaa !19 |
| 68 |
call void @llvm.lifetime.start.p0(ptr %i3), !dbg !66 |
| 69 |
call void @llvm.dbg.declare(metadata ptr %i3, metadata !60, metadata !DIExpression()), !dbg !67 |
| 70 |
store i32 0, ptr %i3, align 4, !dbg !67, !tbaa !19 |
| 71 |
br label %bb7, !dbg !66 |
| 72 |
|
| 73 |
bb7: ; preds = %bb25, %bb |
| 74 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !68 |
| 75 |
%i8 = load i32, ptr %i3, align 4, !dbg !68, !tbaa !19 |
| 76 |
%i9 = icmp slt i32 %i8, 1000000000, !dbg !70 |
| 77 |
br i1 %i9, label %bb12, label %bb10, !dbg !71 |
| 78 |
|
| 79 |
bb10: ; preds = %bb7 |
| 80 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !72 |
| 81 |
call void @llvm.lifetime.end.p0(ptr %i3), !dbg !72 |
| 82 |
br label %bb28 |
| 83 |
|
| 84 |
bb12: ; preds = %bb7 |
| 85 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !73 |
| 86 |
%i13 = load i32, ptr %i3, align 4, !dbg !73, !tbaa !19 |
| 87 |
%i14 = srem i32 %i13, 100, !dbg !76 |
| 88 |
%i15 = icmp eq i32 %i14, 0, !dbg !77 |
| 89 |
br i1 %i15, label %bb16, label %bb17, !dbg !78 |
| 90 |
|
| 91 |
bb16: ; preds = %bb12 |
| 92 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg !79 |
| 93 |
store ptr @bar, ptr %i1, align 8, !dbg !79, !tbaa !45 |
| 94 |
br label %bb18, !dbg !80 |
| 95 |
|
| 96 |
bb17: ; preds = %bb12 |
| 97 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 6, i32 0, i64 -1), !dbg !81 |
| 98 |
store ptr @baz, ptr %i1, align 8, !dbg !81, !tbaa !45 |
| 99 |
br label %bb18 |
| 100 |
|
| 101 |
bb18: ; preds = %bb17, %bb16 |
| 102 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 7, i32 0, i64 -1), !dbg !82 |
| 103 |
%i19 = load i32, ptr %i3, align 4, !dbg !82, !tbaa !19 |
| 104 |
%i20 = load ptr, ptr %i1, align 8, !dbg !83, !tbaa !45 |
| 105 |
%i22 = call i32 @foo(i32 %i19, ptr %i20), !dbg !84 |
| 106 |
%i23 = load i32, ptr %i2, align 4, !dbg !86, !tbaa !19 |
| 107 |
%i24 = add nsw i32 %i23, %i22, !dbg !86 |
| 108 |
store i32 %i24, ptr %i2, align 4, !dbg !86, !tbaa !19 |
| 109 |
br label %bb25, !dbg !87 |
| 110 |
|
| 111 |
bb25: ; preds = %bb18 |
| 112 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !88 |
| 113 |
%i26 = load i32, ptr %i3, align 4, !dbg !88, !tbaa !19 |
| 114 |
%i27 = add nsw i32 %i26, 1, !dbg !88 |
| 115 |
store i32 %i27, ptr %i3, align 4, !dbg !88, !tbaa !19 |
| 116 |
br label %bb7, !dbg !72, !llvm.loop !89 |
| 117 |
|
| 118 |
bb28: ; preds = %bb10 |
| 119 |
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg !92 |
| 120 |
%i29 = load i32, ptr %i2, align 4, !dbg !92, !tbaa !19 |
| 121 |
%i30 = call i32 (ptr, ...) @printf(ptr @.str, i32 %i29), !dbg !93 |
| 122 |
call void @llvm.lifetime.end.p0(ptr %i2), !dbg !95 |
| 123 |
call void @llvm.lifetime.end.p0(ptr %i1), !dbg !95 |
| 124 |
ret i32 0, !dbg !96 |
| 125 |
} |
| 126 |
|
| 127 |
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) |
| 128 |
declare void @llvm.lifetime.start.p0(ptr nocapture) #2 |
| 129 |
|
| 130 |
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) |
| 131 |
declare void @llvm.lifetime.end.p0(ptr nocapture) #2 |
| 132 |
|
| 133 |
declare dso_local i32 @printf(ptr, ...) |
| 134 |
|
| 135 |
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) |
| 136 |
declare void @llvm.pseudoprobe(i64, i64, i32, i64) #3 |
| 137 |
|
| 138 |
attributes #0 = { nounwind uwtable "use-sample-profile" } |
| 139 |
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } |
| 140 |
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } |
| 141 |
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) } |
| 142 |
|
| 143 |
!llvm.dbg.cu = !{!0} |
| 144 |
!llvm.module.flags = !{!3, !4, !5, !6, !7} |
| 145 |
!llvm.ident = !{!8} |
| 146 |
!llvm.pseudo_probe_desc = !{!9, !10, !11, !12} |
| 147 |
|
| 148 |
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.06)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) |
| 149 |
!1 = !DIFile(filename: "test.c", directory: "") |
| 150 |
!2 = !{} |
| 151 |
!3 = !{i32 7, !"Dwarf Version", i32 4} |
| 152 |
!4 = !{i32 2, !"Debug Info Version", i32 3} |
| 153 |
!5 = !{i32 1, !"wchar_size", i32 4} |
| 154 |
!6 = !{i32 1, !"ThinLTO", i32 0} |
| 155 |
!7 = !{i32 1, !"EnableSplitLTOUnit", i32 1} |
| 156 |
!8 = !{!"clang version 13.0.0 "} |
| 157 |
!9 = !{i64 -2012135647395072713, i64 4294967295, !"bar", null} |
| 158 |
!10 = !{i64 7546896869197086323, i64 4294967295, !"baz", null} |
| 159 |
!11 = !{i64 6699318081062747564, i64 281479271677951, !"foo", null} |
| 160 |
!12 = !{i64 -2624081020897602054, i64 563125815542069, !"main", null} |
| 161 |
!13 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 2, type: !14, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !17) |
| 162 |
!14 = !DISubroutineType(types: !15) |
| 163 |
!15 = !{!16, !16} |
| 164 |
!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 165 |
!17 = !{!18} |
| 166 |
!18 = !DILocalVariable(name: "x", arg: 1, scope: !13, file: !1, line: 2, type: !16) |
| 167 |
!19 = !{!20, !20, i64 0} |
| 168 |
!20 = !{!"int", !21, i64 0} |
| 169 |
!21 = !{!"omnipotent char", !22, i64 0} |
| 170 |
!22 = !{!"Simple C/C++ TBAA"} |
| 171 |
!23 = !DILocation(line: 2, column: 13, scope: !13) |
| 172 |
!24 = !DILocation(line: 4, column: 7, scope: !13) |
| 173 |
!25 = !DILocation(line: 5, column: 12, scope: !13) |
| 174 |
!26 = !DILocation(line: 5, column: 14, scope: !13) |
| 175 |
!27 = !DILocation(line: 5, column: 5, scope: !13) |
| 176 |
!28 = distinct !DISubprogram(name: "baz", scope: !1, file: !1, line: 9, type: !14, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !29) |
| 177 |
!29 = !{!30} |
| 178 |
!30 = !DILocalVariable(name: "x", arg: 1, scope: !28, file: !1, line: 9, type: !16) |
| 179 |
!31 = !DILocation(line: 9, column: 13, scope: !28) |
| 180 |
!32 = !DILocation(line: 10, column: 10, scope: !28) |
| 181 |
!33 = !DILocation(line: 10, column: 12, scope: !28) |
| 182 |
!34 = !DILocation(line: 10, column: 3, scope: !28) |
| 183 |
!35 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !36, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !41) |
| 184 |
!36 = !DISubroutineType(types: !37) |
| 185 |
!37 = !{!16, !16, !38} |
| 186 |
!38 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !39, size: 64) |
| 187 |
!39 = !DISubroutineType(types: !40) |
| 188 |
!40 = !{!16, null} |
| 189 |
!41 = !{!42, !43} |
| 190 |
!42 = !DILocalVariable(name: "x", arg: 1, scope: !35, file: !1, line: 13, type: !16) |
| 191 |
!43 = !DILocalVariable(name: "f", arg: 2, scope: !35, file: !1, line: 13, type: !38) |
| 192 |
!44 = !DILocation(line: 13, column: 13, scope: !35) |
| 193 |
!45 = !{!46, !46, i64 0} |
| 194 |
!46 = !{!"any pointer", !21, i64 0} |
| 195 |
!47 = !DILocation(line: 13, column: 22, scope: !35) |
| 196 |
!48 = !DILocation(line: 14, column: 10, scope: !35) |
| 197 |
!49 = !DILocation(line: 14, column: 12, scope: !35) |
| 198 |
!50 = !DILocation(line: 14, column: 10, scope: !51) |
| 199 |
;; A discriminator of 108527639 which is 0x6780017 in hexdecimal, stands for an indirect call probe |
| 200 |
;; with an index of 2 and probe factor of 0.79. |
| 201 |
!51 = !DILexicalBlockFile(scope: !35, file: !1, discriminator: 108527639) |
| 202 |
!52 = !DILocation(line: 14, column: 3, scope: !35) |
| 203 |
!53 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 17, type: !54, scopeLine: 18, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !56) |
| 204 |
!54 = !DISubroutineType(types: !55) |
| 205 |
!55 = !{!16} |
| 206 |
!56 = !{!57, !59, !60} |
| 207 |
!57 = !DILocalVariable(name: "x", scope: !53, file: !1, line: 19, type: !58) |
| 208 |
!58 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) |
| 209 |
!59 = !DILocalVariable(name: "sum", scope: !53, file: !1, line: 25, type: !16) |
| 210 |
!60 = !DILocalVariable(name: "i", scope: !61, file: !1, line: 26, type: !16) |
| 211 |
!61 = distinct !DILexicalBlock(scope: !53, file: !1, line: 26, column: 5) |
| 212 |
!62 = !DILocation(line: 19, column: 3, scope: !53) |
| 213 |
!63 = !DILocation(line: 19, column: 9, scope: !53) |
| 214 |
!64 = !DILocation(line: 25, column: 5, scope: !53) |
| 215 |
!65 = !DILocation(line: 25, column: 9, scope: !53) |
| 216 |
!66 = !DILocation(line: 26, column: 10, scope: !61) |
| 217 |
!67 = !DILocation(line: 26, column: 14, scope: !61) |
| 218 |
!68 = !DILocation(line: 26, column: 21, scope: !69) |
| 219 |
!69 = distinct !DILexicalBlock(scope: !61, file: !1, line: 26, column: 5) |
| 220 |
!70 = !DILocation(line: 26, column: 23, scope: !69) |
| 221 |
!71 = !DILocation(line: 26, column: 5, scope: !61) |
| 222 |
!72 = !DILocation(line: 26, column: 5, scope: !69) |
| 223 |
!73 = !DILocation(line: 27, column: 10, scope: !74) |
| 224 |
!74 = distinct !DILexicalBlock(scope: !75, file: !1, line: 27, column: 10) |
| 225 |
!75 = distinct !DILexicalBlock(scope: !69, file: !1, line: 26, column: 45) |
| 226 |
!76 = !DILocation(line: 27, column: 12, scope: !74) |
| 227 |
!77 = !DILocation(line: 27, column: 19, scope: !74) |
| 228 |
!78 = !DILocation(line: 27, column: 10, scope: !75) |
| 229 |
!79 = !DILocation(line: 28, column: 11, scope: !74) |
| 230 |
!80 = !DILocation(line: 28, column: 9, scope: !74) |
| 231 |
!81 = !DILocation(line: 30, column: 11, scope: !74) |
| 232 |
!82 = !DILocation(line: 32, column: 17, scope: !75) |
| 233 |
!83 = !DILocation(line: 32, column: 20, scope: !75) |
| 234 |
!84 = !DILocation(line: 32, column: 13, scope: !85) |
| 235 |
;; A discriminator of 116916311 which is 0x6f80057 in hexdecimal, stands for an indirect call probe |
| 236 |
;; with an index of 10 and probe factor of 0.95. |
| 237 |
!85 = !DILexicalBlockFile(scope: !75, file: !1, discriminator: 116916311) |
| 238 |
!86 = !DILocation(line: 32, column: 11, scope: !75) |
| 239 |
!87 = !DILocation(line: 33, column: 5, scope: !75) |
| 240 |
!88 = !DILocation(line: 26, column: 41, scope: !69) |
| 241 |
!89 = distinct !{!89, !71, !90, !91} |
| 242 |
!90 = !DILocation(line: 33, column: 5, scope: !61) |
| 243 |
!91 = !{!"llvm.loop.mustprogress"} |
| 244 |
!92 = !DILocation(line: 34, column: 21, scope: !53) |
| 245 |
!93 = !DILocation(line: 34, column: 5, scope: !94) |
| 246 |
!94 = !DILexicalBlockFile(scope: !53, file: !1, discriminator: 104333335) |
| 247 |
!95 = !DILocation(line: 36, column: 1, scope: !53) |
| 248 |
!96 = !DILocation(line: 35, column: 5, scope: !53) |
| 249 |
|
| 250 |
; CHECK: define dso_local i32 @main |
| 251 |
; CHECK: %{{.+}} = call i32 (i32, ...) %{{.+}}(i32 %{{.+}}) #[[#]], !dbg ![[#DBGID:]], !prof ![[#PROF:]] |
| 252 |
|
| 253 |
;; A discriminator of 106430487 which is 0x6580017 in hexdecimal, stands for an indirect call probe |
| 254 |
;; with an index of 2 and probe factor of 0.75, which is from 0.95 * 0.79. |
| 255 |
; CHECK: ![[#DBGID]] = !DILocation(line: [[#]], column: [[#]], scope: ![[#SCOPE:]], inlinedAt: ![[#]]) |
| 256 |
; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 106430487) |
| 257 |
|
| 258 |
;; The remaining count of the second target (bar) should be from the original count multiplied by two callsite |
| 259 |
;; factors, i.e, roughly 11259 * 0.95 * 0.79 = 8444. |
| 260 |
; CHECK: ![[#PROF]] = !{!"VP", i32 0, i64 8444, i64 7546896869197086323, i64 -1, i64 -2012135647395072713, i64 8444} |