[PATCH] D32624: Memory intrinsic value profile optimization: Avoid divide by 0

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 28 07:44:06 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL301645: Memory intrinsic value profile optimization: Avoid divide by 0 (authored by tejohnson).

Changed prior to commit:
  https://reviews.llvm.org/D32624?vs=97018&id=97096#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32624

Files:
  llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
  llvm/trunk/test/Transforms/PGOProfile/memop_size_opt_zero.ll


Index: llvm/trunk/test/Transforms/PGOProfile/memop_size_opt_zero.ll
===================================================================
--- llvm/trunk/test/Transforms/PGOProfile/memop_size_opt_zero.ll
+++ llvm/trunk/test/Transforms/PGOProfile/memop_size_opt_zero.ll
@@ -0,0 +1,19 @@
+; Test to ensure the pgo memop optimization pass doesn't try to scale
+; up a value profile with a 0 count, which would lead to divide by 0.
+; RUN: opt < %s -passes=pgo-memop-opt -pgo-memop-count-threshold=1 -S | FileCheck %s --check-prefix=MEMOP_OPT
+; RUN: opt < %s -pgo-memop-opt -pgo-memop-count-threshold=1 -S | FileCheck %s --check-prefix=MEMOP_OPT
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo(i8* %dst, i8* %src, i64 %conv) !prof !0 {
+  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false), !prof !1
+  ret void
+}
+
+; MEMOP_OPT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %conv, i32 1, i1 false), !prof !1
+
+!0 = !{!"function_entry_count", i64 1}
+!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}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
Index: llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -872,6 +872,10 @@
 
   if (ActualCount < MemOPCountThreshold)
     return false;
+  // Skip if the total value profiled count is 0, in which case we can't
+  // scale up the counts properly (and there is no profitable transformation).
+  if (TotalCount == 0)
+    return false;
 
   TotalCount = ActualCount;
   if (MemOPScaleCount)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32624.97096.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170428/385f6226/attachment.bin>


More information about the llvm-commits mailing list