Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 4a6d61a

Browse files
committed
Memory intrinsic value profile optimization: Avoid divide by 0
Summary: Skip memops if the total value profiled count is 0, we can't correctly scale up the counts and there is no point anyway. Reviewers: davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32624 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301645 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 053e5ff commit 4a6d61a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ bool MemOPSizeOpt::perform(MemIntrinsic *MI) {
872872

873873
if (ActualCount < MemOPCountThreshold)
874874
return false;
875+
// Skip if the total value profiled count is 0, in which case we can't
876+
// scale up the counts properly (and there is no profitable transformation).
877+
if (TotalCount == 0)
878+
return false;
875879

876880
TotalCount = ActualCount;
877881
if (MemOPScaleCount)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Test to ensure the pgo memop optimization pass doesn't try to scale
2+
; up a value profile with a 0 count, which would lead to divide by 0.
3+
; RUN: opt < %s -passes=pgo-memop-opt -pgo-memop-count-threshold=1 -S | FileCheck %s --check-prefix=MEMOP_OPT
4+
; RUN: opt < %s -pgo-memop-opt -pgo-memop-count-threshold=1 -S | FileCheck %s --check-prefix=MEMOP_OPT
5+
6+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-unknown-linux-gnu"
8+
9+
define void @foo(i8* %dst, i8* %src, i64 %conv) !prof !0 {
10+
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false), !prof !1
11+
ret void
12+
}
13+
14+
; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false), !prof !1
15+
16+
!0 = !{!"function_entry_count", i64 1}
17+
!1 = !{!"VP", i32 1, i64 0, i64 1, i64 0, i64 2, i64 0, i64 3, i64 0, i64 9, i64 0, i64 4, i64 0, i64 5, i64 0, i64 6, i64 0, i64 7, i64 0, i64 8, i64 0}
18+
19+
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)

0 commit comments

Comments
 (0)