summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2017-08-29 15:28:12 +0000
committerDehao Chen <dehao@google.com>2017-08-29 15:28:12 +0000
commitefd007f6f4dc77655a8a266f325d6b31376224d8 (patch)
tree247c1208a7b256943460dcc17ae2d36b6ef007a4
parentdb21e5324a0ce7b920394288b5b9bea00b231e6c (diff)
downloadbcm5719-llvm-efd007f6f4dc77655a8a266f325d6b31376224d8.tar.gz
bcm5719-llvm-efd007f6f4dc77655a8a266f325d6b31376224d8.zip
Add null check for promoted direct call
Summary: We originally assume that in pgo-icp, the promoted direct call will never be null after strip point casts. However, stripPointerCasts is so smart that it could possibly return the value of the function call if it knows that the return value is always an argument. In this case, the returned value cannot cast to Instruction. In this patch, null check is added to ensure null pointer will not be accessed. Reviewers: tejohnson, xur, davidxl, djasper Reviewed By: tejohnson Subscribers: llvm-commits, sanjoy Differential Revision: https://reviews.llvm.org/D37252 llvm-svn: 312005
-rw-r--r--llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp4
-rw-r--r--llvm/test/Transforms/PGOProfile/icp_sample.ll44
2 files changed, 46 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 1cf8090b02c..f323e081495 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -566,8 +566,8 @@ Instruction *llvm::promoteIndirectCall(Instruction *Inst,
SmallVector<uint32_t, 1> Weights;
Weights.push_back(Count);
MDBuilder MDB(NewInst->getContext());
- dyn_cast<Instruction>(NewInst->stripPointerCasts())
- ->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
+ if (Instruction *DI = dyn_cast<Instruction>(NewInst->stripPointerCasts()))
+ DI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
}
// Move Inst from MergeBB to IndirectCallBB.
diff --git a/llvm/test/Transforms/PGOProfile/icp_sample.ll b/llvm/test/Transforms/PGOProfile/icp_sample.ll
new file mode 100644
index 00000000000..73922d7aa06
--- /dev/null
+++ b/llvm/test/Transforms/PGOProfile/icp_sample.ll
@@ -0,0 +1,44 @@
+; RUN: opt -pgo-icall-prom -icp-samplepgo -S < %s | FileCheck %s
+
+define i32* @_Z3fooPi(i32* readnone returned) {
+ ret i32* %0
+}
+
+; CHECK-LABEL: _Z3barPFPiS_E
+; CHECK: if.true.direct_targ
+; CHECK: call i32* @_Z3fooPi
+define i32* @_Z3barPFPiS_E(i32* (i32*)* nocapture) {
+ %2 = tail call i32* %0(i32* null), !prof !33
+ ret i32* %2
+}
+
+!llvm.module.flags = !{!3}
+
+!3 = !{i32 1, !"ProfileSummary", !4}
+!4 = !{!5, !6, !7, !8, !9, !10, !11, !12}
+!5 = !{!"ProfileFormat", !"SampleProfile"}
+!6 = !{!"TotalCount", i64 0}
+!7 = !{!"MaxCount", i64 0}
+!8 = !{!"MaxInternalCount", i64 0}
+!9 = !{!"MaxFunctionCount", i64 0}
+!10 = !{!"NumCounts", i64 1}
+!11 = !{!"NumFunctions", i64 1}
+!12 = !{!"DetailedSummary", !13}
+!13 = !{!14, !15, !16, !17, !18, !19, !19, !20, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29}
+!14 = !{i32 10000, i64 0, i32 0}
+!15 = !{i32 100000, i64 0, i32 0}
+!16 = !{i32 200000, i64 0, i32 0}
+!17 = !{i32 300000, i64 0, i32 0}
+!18 = !{i32 400000, i64 0, i32 0}
+!19 = !{i32 500000, i64 0, i32 0}
+!20 = !{i32 600000, i64 0, i32 0}
+!21 = !{i32 700000, i64 0, i32 0}
+!22 = !{i32 800000, i64 0, i32 0}
+!23 = !{i32 900000, i64 0, i32 0}
+!24 = !{i32 950000, i64 0, i32 0}
+!25 = !{i32 990000, i64 0, i32 0}
+!26 = !{i32 999000, i64 0, i32 0}
+!27 = !{i32 999900, i64 0, i32 0}
+!28 = !{i32 999990, i64 0, i32 0}
+!29 = !{i32 999999, i64 0, i32 0}
+!33 = !{!"VP", i32 0, i64 100, i64 8400159624858369790, i64 100}
OpenPOWER on IntegriCloud