1 ; RUN: opt < %s -pgo-memop-opt -verify-dom-info -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -pgo-memop-optimize-memcmp-bcmp -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 --pgo-memop-optimize-memcmp-bcmp -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 -pgo-memop-optimize-memcmp-bcmp -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 -pgo-memop-optimize-memcmp-bcmp -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 0, 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 0, 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 0, 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 0, 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
62 %inc = add nsw i32 %j.0, 1
69 %inc5 = add nsw i32 %i.0, 1
76 declare void @consume(i32 %v1, i32 %v2)
78 define void @foo_memcmp_bcmp(i8* %dst, i8* %src, i8* %dst2, i8* %src2, i32* %a, i32 %n) !prof !27 {
83 %i.0 = phi i32 [ 0, %entry ], [ %inc5, %for.inc4 ]
84 %cmp = icmp slt i32 %i.0, %n
85 br i1 %cmp, label %for.body, label %for.end6, !prof !28
91 %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ]
92 %idx.ext = sext i32 %i.0 to i64
93 %add.ptr = getelementptr inbounds i32, i32* %a, i64 %idx.ext
94 %0 = load i32, i32* %add.ptr, align 4
95 %cmp2 = icmp slt i32 %j.0, %0
96 br i1 %cmp2, label %for.body3, label %for.end, !prof !29
99 %add = add nsw i32 %i.0, 1
100 %conv = sext i32 %add to i64
101 %memcmp = call i32 @memcmp(i8* %dst, i8* %src, i64 %conv), !prof !30
102 %bcmp = call i32 @bcmp(i8* %dst2, i8* %src2, i64 %conv), !prof !31
103 call void @consume(i32 %memcmp, i32 %bcmp)
106 ; MEMOP_OPT: switch i64 %conv, label %[[DEFAULT_LABEL:.*]] [
107 ; MEMOP_OPT: i64 0, label %[[CASE_1_LABEL:.*]]
108 ; MEMOP_OPT: ], !prof [[SWITCH_BW:![0-9]+]]
109 ; MEMOP_OPT: [[CASE_1_LABEL]]:
110 ; MEMOP_OPT: %[[RV:.*]] = call i32 @memcmp(i8* %dst, i8* %src, i64 0)
111 ; MEMOP_OPT: br label %[[MERGE_LABEL:.*]]
112 ; MEMOP_OPT: [[DEFAULT_LABEL]]:
113 ; MEMOP_OPT: %[[RVD:.*]] = call i32 @memcmp(i8* %dst, i8* %src, i64 %conv), !prof [[NEWVP:![0-9]+]]
114 ; MEMOP_OPT: br label %[[MERGE_LABEL]]
115 ; MEMOP_OPT: [[MERGE_LABEL]]:
116 ; MEMOP_OPT: %[[PHI:.*]] = phi i32 [ %[[RVD]], %[[DEFAULT_LABEL]] ], [ %[[RV]], %[[CASE_1_LABEL]] ]
117 ; MEMOP_OPT: switch i64 %conv, label %[[DEFAULT_LABEL2:.*]] [
118 ; MEMOP_OPT: i64 0, label %[[CASE_1_LABEL2:.*]]
119 ; MEMOP_OPT: ], !prof [[SWITCH_BW:![0-9]+]]
120 ; MEMOP_OPT: [[CASE_1_LABEL2]]:
121 ; MEMOP_OPT: %[[RV2:.*]] = call i32 @bcmp(i8* %dst2, i8* %src2, i64 0)
122 ; MEMOP_OPT: br label %[[MERGE_LABEL2:.*]]
123 ; MEMOP_OPT: [[DEFAULT_LABEL2]]:
124 ; MEMOP_OPT: %[[RVD2:.*]] = call i32 @bcmp(i8* %dst2, i8* %src2, i64 %conv), !prof [[NEWVP]]
125 ; MEMOP_OPT: br label %[[MERGE_LABEL2]]
126 ; MEMOP_OPT: [[MERGE_LABEL2]]:
127 ; MEMOP_OPT: %[[PHI2:.*]] = phi i32 [ %[[RVD2]], %[[DEFAULT_LABEL2]] ], [ %[[RV2]], %[[CASE_1_LABEL2]] ]
128 ; MEMOP_OPT: call void @consume(i32 %[[PHI]], i32 %[[PHI2]])
129 ; MEMOP_OPT: br label %for.inc
132 %inc = add nsw i32 %j.0, 1
139 %inc5 = add nsw i32 %i.0, 1
146 ; MEMOP_OPT: [[SWITCH_BW]] = !{!"branch_weights", i32 457, i32 99}
147 ; Should be 457 total left (original total count 556, minus 99 from specialized
148 ; value 0, which is removed from VP array. This should preserve all unpromoted values.
149 ; MEMOP_OPT: [[NEWVP]] = !{!"VP", i32 1, i64 457, 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}
151 !llvm.module.flags = !{!0}
153 !0 = !{i32 1, !"ProfileSummary", !1}
154 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
155 !2 = !{!"ProfileFormat", !"InstrProf"}
156 !3 = !{!"TotalCount", i64 579}
157 !4 = !{!"MaxCount", i64 556}
158 !5 = !{!"MaxInternalCount", i64 20}
159 !6 = !{!"MaxFunctionCount", i64 556}
160 !7 = !{!"NumCounts", i64 6}
161 !8 = !{!"NumFunctions", i64 3}
162 !9 = !{!"DetailedSummary", !10}
163 !10 = !{!11, !12, !13, !14, !15, !16, !16, !17, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26}
164 !11 = !{i32 10000, i64 556, i32 1}
165 !12 = !{i32 100000, i64 556, i32 1}
166 !13 = !{i32 200000, i64 556, i32 1}
167 !14 = !{i32 300000, i64 556, i32 1}
168 !15 = !{i32 400000, i64 556, i32 1}
169 !16 = !{i32 500000, i64 556, i32 1}
170 !17 = !{i32 600000, i64 556, i32 1}
171 !18 = !{i32 700000, i64 556, i32 1}
172 !19 = !{i32 800000, i64 556, i32 1}
173 !20 = !{i32 900000, i64 556, i32 1}
174 !21 = !{i32 950000, i64 556, i32 1}
175 !22 = !{i32 990000, i64 20, i32 2}
176 !23 = !{i32 999000, i64 1, i32 5}
177 !24 = !{i32 999900, i64 1, i32 5}
178 !25 = !{i32 999990, i64 1, i32 5}
179 !26 = !{i32 999999, i64 1, i32 5}
180 !27 = !{!"function_entry_count", i64 1}
181 !28 = !{!"branch_weights", i32 20, i32 1}
182 !29 = !{!"branch_weights", i32 556, i32 20}
183 !30 = !{!"VP", i32 1, i64 556, i64 0, 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}
184 !31 = !{!"VP", i32 1, i64 556, i64 0, 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}
186 declare void @llvm.lifetime.start(i64, i8* nocapture)
188 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1)
190 declare i32 @memcmp(i8*, i8*, i64)
191 declare i32 @bcmp(i8*, i8*, i64)
193 declare void @llvm.lifetime.end(i64, i8* nocapture)
196 ; YAML-NEXT: Pass: pgo-memop-opt
197 ; YAML-NEXT: Name: memopt-opt
198 ; YAML-NEXT: Function: foo
199 ; YAML-NEXT: Hotness: 0
201 ; YAML-NEXT: - String: 'optimized '
202 ; YAML-NEXT: - Memop: memcpy
203 ; YAML-NEXT: - String: ' with count '
204 ; YAML-NEXT: - Count: '99'
205 ; YAML-NEXT: - String: ' out of '
206 ; YAML-NEXT: - Total: '556'
207 ; YAML-NEXT: - String: ' for '
208 ; YAML-NEXT: - Versions: '1'
209 ; YAML-NEXT: - String: ' versions'
211 ; YAML-NEXT: --- !Passed
212 ; YAML-NEXT: Pass: pgo-memop-opt
213 ; YAML-NEXT: Name: memopt-opt
214 ; YAML-NEXT: Function: foo
215 ; YAML-NEXT: Hotness: 0
217 ; YAML-NEXT: - String: 'optimized '
218 ; YAML-NEXT: - Memop: memcpy
219 ; YAML-NEXT: - String: ' with count '
220 ; YAML-NEXT: - Count: '99'
221 ; YAML-NEXT: - String: ' out of '
222 ; YAML-NEXT: - Total: '556'
223 ; YAML-NEXT: - String: ' for '
224 ; YAML-NEXT: - Versions: '1'
225 ; YAML-NEXT: - String: ' versions'
227 ; YAML-NEXT: --- !Passed
228 ; YAML-NEXT: Pass: pgo-memop-opt
229 ; YAML-NEXT: Name: memopt-opt
230 ; YAML-NEXT: Function: foo_memcmp_bcmp
231 ; YAML-NEXT: Hotness: 0
233 ; YAML-NEXT: - String: 'optimized '
234 ; YAML-NEXT: - Memop: memcmp
235 ; YAML-NEXT: - String: ' with count '
236 ; YAML-NEXT: - Count: '99'
237 ; YAML-NEXT: - String: ' out of '
238 ; YAML-NEXT: - Total: '556'
239 ; YAML-NEXT: - String: ' for '
240 ; YAML-NEXT: - Versions: '1'
241 ; YAML-NEXT: - String: ' versions'
243 ; YAML-NEXT: --- !Passed
244 ; YAML-NEXT: Pass: pgo-memop-opt
245 ; YAML-NEXT: Name: memopt-opt
246 ; YAML-NEXT: Function: foo_memcmp_bcmp
247 ; YAML-NEXT: Hotness: 0
249 ; YAML-NEXT: - String: 'optimized '
250 ; YAML-NEXT: - Memop: bcmp
251 ; YAML-NEXT: - String: ' with count '
252 ; YAML-NEXT: - Count: '99'
253 ; YAML-NEXT: - String: ' out of '
254 ; YAML-NEXT: - Total: '556'
255 ; YAML-NEXT: - String: ' for '
256 ; YAML-NEXT: - Versions: '1'
257 ; YAML-NEXT: - String: ' versions'