[llvm] r305321 - [PGO] Update VP metadata after memory intrinsic optimization
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 13 13:44:08 PDT 2017
Author: tejohnson
Date: Tue Jun 13 15:44:08 2017
New Revision: 305321
URL: http://llvm.org/viewvc/llvm-project?rev=305321&view=rev
Log:
[PGO] Update VP metadata after memory intrinsic optimization
Summary:
Leave an updated VP metadata on the fallback memcpy intrinsic after
specialization. This can be used for later possible expansion based on
the average of the remaining values.
Reviewers: davidxl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34164
Modified:
llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
llvm/trunk/test/Transforms/PGOProfile/memop_size_opt.ll
Modified: llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp?rev=305321&r1=305320&r2=305321&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp Tue Jun 13 15:44:08 2017
@@ -884,6 +884,7 @@ bool MemOPSizeOpt::perform(MemIntrinsic
// Keeping track of the count of the default case:
uint64_t RemainCount = TotalCount;
+ uint64_t SavedRemainCount = SavedTotalCount;
SmallVector<uint64_t, 16> SizeIds;
SmallVector<uint64_t, 16> CaseCounts;
uint64_t MaxCount = 0;
@@ -912,6 +913,8 @@ bool MemOPSizeOpt::perform(MemIntrinsic
assert(RemainCount >= C);
RemainCount -= C;
+ assert(SavedRemainCount >= VD.Count);
+ SavedRemainCount -= VD.Count;
if (++Version > MemOPMaxVersion && MemOPMaxVersion != 0)
break;
@@ -968,6 +971,11 @@ bool MemOPSizeOpt::perform(MemIntrinsic
// Clear the value profile data.
MI->setMetadata(LLVMContext::MD_prof, nullptr);
+ // If all promoted, we don't need the MD.prof metadata.
+ if (SavedRemainCount > 0 || Version != NumVals)
+ // Otherwise we need update with the un-promoted records back.
+ annotateValueSite(*Func.getParent(), *MI, VDs.slice(Version),
+ SavedRemainCount, IPVK_MemOPSize, NumVals);
DEBUG(dbgs() << "\n\n== Basic Block After==\n");
Modified: llvm/trunk/test/Transforms/PGOProfile/memop_size_opt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/memop_size_opt.ll?rev=305321&r1=305320&r2=305321&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/memop_size_opt.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/memop_size_opt.ll Tue Jun 13 15:44:08 2017
@@ -38,7 +38,7 @@ for.body3:
; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 1, i32 1, i1 false)
; MEMOP_OPT: br label %[[MERGE_LABEL:.*]]
; MEMOP_OPT: [[DEFAULT_LABEL]]:
-; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false){{[[:space:]]}}
+; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false), !prof [[NEWVP:![0-9]+]]
; MEMOP_OPT: br label %[[MERGE_LABEL]]
; MEMOP_OPT: [[MERGE_LABEL]]:
; MEMOP_OPT: switch i64 %conv, label %[[DEFAULT_LABEL2:.*]] [
@@ -48,11 +48,16 @@ for.body3:
; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 1, i32 1, i1 false)
; MEMOP_OPT: br label %[[MERGE_LABEL2:.*]]
; MEMOP_OPT: [[DEFAULT_LABEL2]]:
-; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 %conv, i32 1, i1 false){{[[:space:]]}}
+; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src2, i64 %conv, i32 1, i1 false), !prof [[NEWVP]]
; MEMOP_OPT: br label %[[MERGE_LABEL2]]
; MEMOP_OPT: [[MERGE_LABEL2]]:
; MEMOP_OPT: br label %for.inc
; MEMOP_OPT: [[SWITCH_BW]] = !{!"branch_weights", i32 457, i32 99}
+; Should be 457 total left (original total count 556, minus 99 from specialized
+; value 1, which is removed from VP array. Also, we only end up with 5 total
+; values, since the default max number of promotions is 5 and therefore
+; the rest of the values are ignored when extracting the VP metadata.
+; MEMOP_OPT: [[NEWVP]] = !{!"VP", i32 1, i64 457, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66}
for.inc:
%inc = add nsw i32 %j.0, 1
More information about the llvm-commits
mailing list