1 ; RUN: opt < %s -pgo-memop-opt -verify-dom-info -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -S | FileCheck %s --check-prefix=MEMOP_OPT
2 ; RUN: opt < %s -passes=pgo-memop-opt -verify-dom-info -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -S | FileCheck %s --check-prefix=MEMOP_OPT
3 ; RUN: opt < %s -pgo-memop-opt -verify-dom-info -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -pass-remarks-with-hotness -pass-remarks-output=%t.opt.yaml -S | FileCheck %s --check-prefix=MEMOP_OPT
4 ; RUN: FileCheck %s -input-file=%t.opt.yaml --check-prefix=YAML
5 ; RUN: opt < %s -passes=pgo-memop-opt -verify-dom-info -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -pass-remarks-with-hotness -pass-remarks-output=%t.opt.yaml -S | FileCheck %s --check-prefix=MEMOP_OPT
6 ; RUN: FileCheck %s -input-file=%t.opt.yaml --check-prefix=YAML
9 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
12 define void @foo(i8* %dst, i8* %src, i8* %dst2, i8* %src2, i32* %a, i32 %n) !prof !27 {
17 %i.0 = phi i32 [ 0, %entry ], [ %inc5, %for.inc4 ]
18 %cmp = icmp slt i32 %i.0, %n
19 br i1 %cmp, label %for.body, label %for.end6, !prof !28
25 %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ]
26 %idx.ext = sext i32 %i.0 to i64
27 %add.ptr = getelementptr inbounds i32, i32* %a, i64 %idx.ext
28 %0 = load i32, i32* %add.ptr, align 4
29 %cmp2 = icmp slt i32 %j.0, %0
30 br i1 %cmp2, label %for.body3, label %for.end, !prof !29
33 %add = add nsw i32 %i.0, 1
34 %conv = sext i32 %add to i64
35 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i1 false), !prof !30
36 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 %conv, i1 false), !prof !31
39 ; MEMOP_OPT: switch i64 %conv, label %[[DEFAULT_LABEL:.*]] [
40 ; MEMOP_OPT: i64 1, label %[[CASE_1_LABEL:.*]]
41 ; MEMOP_OPT: ], !prof [[SWITCH_BW:![0-9]+]]
42 ; MEMOP_OPT: [[CASE_1_LABEL]]:
43 ; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 1, i1 false)
44 ; MEMOP_OPT: br label %[[MERGE_LABEL:.*]]
45 ; MEMOP_OPT: [[DEFAULT_LABEL]]:
46 ; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i1 false), !prof [[NEWVP:![0-9]+]]
47 ; MEMOP_OPT: br label %[[MERGE_LABEL]]
48 ; MEMOP_OPT: [[MERGE_LABEL]]:
49 ; MEMOP_OPT: switch i64 %conv, label %[[DEFAULT_LABEL2:.*]] [
50 ; MEMOP_OPT: i64 1, label %[[CASE_1_LABEL2:.*]]
51 ; MEMOP_OPT: ], !prof [[SWITCH_BW:![0-9]+]]
52 ; MEMOP_OPT: [[CASE_1_LABEL2]]:
53 ; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 1, i1 false)
54 ; MEMOP_OPT: br label %[[MERGE_LABEL2:.*]]
55 ; MEMOP_OPT: [[DEFAULT_LABEL2]]:
56 ; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 %conv, i1 false), !prof [[NEWVP]]
57 ; MEMOP_OPT: br label %[[MERGE_LABEL2]]
58 ; MEMOP_OPT: [[MERGE_LABEL2]]:
59 ; MEMOP_OPT: br label %for.inc
60 ; MEMOP_OPT: [[SWITCH_BW]] = !{!"branch_weights", i32 457, i32 99}
61 ; Should be 457 total left (original total count 556, minus 99 from specialized
62 ; value 1, which is removed from VP array. Also, we only end up with 5 total
63 ; values, since the default max number of promotions is 5 and therefore
64 ; the rest of the values are ignored when extracting the VP metadata.
65 ; MEMOP_OPT: [[NEWVP]] = !{!"VP", i32 1, i64 457, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66}
68 %inc = add nsw i32 %j.0, 1
75 %inc5 = add nsw i32 %i.0, 1
82 !llvm.module.flags = !{!0}
84 !0 = !{i32 1, !"ProfileSummary", !1}
85 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
86 !2 = !{!"ProfileFormat", !"InstrProf"}
87 !3 = !{!"TotalCount", i64 579}
88 !4 = !{!"MaxCount", i64 556}
89 !5 = !{!"MaxInternalCount", i64 20}
90 !6 = !{!"MaxFunctionCount", i64 556}
91 !7 = !{!"NumCounts", i64 6}
92 !8 = !{!"NumFunctions", i64 3}
93 !9 = !{!"DetailedSummary", !10}
94 !10 = !{!11, !12, !13, !14, !15, !16, !16, !17, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26}
95 !11 = !{i32 10000, i64 556, i32 1}
96 !12 = !{i32 100000, i64 556, i32 1}
97 !13 = !{i32 200000, i64 556, i32 1}
98 !14 = !{i32 300000, i64 556, i32 1}
99 !15 = !{i32 400000, i64 556, i32 1}
100 !16 = !{i32 500000, i64 556, i32 1}
101 !17 = !{i32 600000, i64 556, i32 1}
102 !18 = !{i32 700000, i64 556, i32 1}
103 !19 = !{i32 800000, i64 556, i32 1}
104 !20 = !{i32 900000, i64 556, i32 1}
105 !21 = !{i32 950000, i64 556, i32 1}
106 !22 = !{i32 990000, i64 20, i32 2}
107 !23 = !{i32 999000, i64 1, i32 5}
108 !24 = !{i32 999900, i64 1, i32 5}
109 !25 = !{i32 999990, i64 1, i32 5}
110 !26 = !{i32 999999, i64 1, i32 5}
111 !27 = !{!"function_entry_count", i64 1}
112 !28 = !{!"branch_weights", i32 20, i32 1}
113 !29 = !{!"branch_weights", i32 556, i32 20}
114 !30 = !{!"VP", i32 1, i64 556, i64 1, i64 99, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66, i64 5, i64 55, i64 6, i64 44, i64 7, i64 33, i64 8, i64 22}
115 !31 = !{!"VP", i32 1, i64 556, i64 1, i64 99, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66, i64 5, i64 55, i64 6, i64 44, i64 7, i64 33, i64 8, i64 22}
117 declare void @llvm.lifetime.start(i64, i8* nocapture)
119 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1)
121 declare void @llvm.lifetime.end(i64, i8* nocapture)
124 ; YAML-NEXT: Pass: pgo-memop-opt
125 ; YAML-NEXT: Name: memopt-opt
126 ; YAML-NEXT: Function: foo
127 ; YAML-NEXT: Hotness: 0
129 ; YAML-NEXT: - String: 'optimized '
130 ; YAML-NEXT: - Intrinsic: memcpy
131 ; YAML-NEXT: - String: ' with count '
132 ; YAML-NEXT: - Count: '99'
133 ; YAML-NEXT: - String: ' out of '
134 ; YAML-NEXT: - Total: '556'
135 ; YAML-NEXT: - String: ' for '
136 ; YAML-NEXT: - Versions: '1'
137 ; YAML-NEXT: - String: ' versions'
139 ; YAML-NEXT: --- !Passed
140 ; YAML-NEXT: Pass: pgo-memop-opt
141 ; YAML-NEXT: Name: memopt-opt
142 ; YAML-NEXT: Function: foo
143 ; YAML-NEXT: Hotness: 0
145 ; YAML-NEXT: - String: 'optimized '
146 ; YAML-NEXT: - Intrinsic: memcpy
147 ; YAML-NEXT: - String: ' with count '
148 ; YAML-NEXT: - Count: '99'
149 ; YAML-NEXT: - String: ' out of '
150 ; YAML-NEXT: - Total: '556'
151 ; YAML-NEXT: - String: ' for '
152 ; YAML-NEXT: - Versions: '1'
153 ; YAML-NEXT: - String: ' versions'