llvm.org GIT mirror llvm / 31ec888
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312005 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 2 years ago
2 changed file(s) with 46 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
565565 SmallVector Weights;
566566 Weights.push_back(Count);
567567 MDBuilder MDB(NewInst->getContext());
568 dyn_cast(NewInst->stripPointerCasts())
569 ->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
568 if (Instruction *DI = dyn_cast(NewInst->stripPointerCasts()))
569 DI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
570570 }
571571
572572 // Move Inst from MergeBB to IndirectCallBB.
0 ; RUN: opt -pgo-icall-prom -icp-samplepgo -S < %s | FileCheck %s
1
2 define i32* @_Z3fooPi(i32* readnone returned) {
3 ret i32* %0
4 }
5
6 ; CHECK-LABEL: _Z3barPFPiS_E
7 ; CHECK: if.true.direct_targ
8 ; CHECK: call i32* @_Z3fooPi
9 define i32* @_Z3barPFPiS_E(i32* (i32*)* nocapture) {
10 %2 = tail call i32* %0(i32* null), !prof !33
11 ret i32* %2
12 }
13
14 !llvm.module.flags = !{!3}
15
16 !3 = !{i32 1, !"ProfileSummary", !4}
17 !4 = !{!5, !6, !7, !8, !9, !10, !11, !12}
18 !5 = !{!"ProfileFormat", !"SampleProfile"}
19 !6 = !{!"TotalCount", i64 0}
20 !7 = !{!"MaxCount", i64 0}
21 !8 = !{!"MaxInternalCount", i64 0}
22 !9 = !{!"MaxFunctionCount", i64 0}
23 !10 = !{!"NumCounts", i64 1}
24 !11 = !{!"NumFunctions", i64 1}
25 !12 = !{!"DetailedSummary", !13}
26 !13 = !{!14, !15, !16, !17, !18, !19, !19, !20, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29}
27 !14 = !{i32 10000, i64 0, i32 0}
28 !15 = !{i32 100000, i64 0, i32 0}
29 !16 = !{i32 200000, i64 0, i32 0}
30 !17 = !{i32 300000, i64 0, i32 0}
31 !18 = !{i32 400000, i64 0, i32 0}
32 !19 = !{i32 500000, i64 0, i32 0}
33 !20 = !{i32 600000, i64 0, i32 0}
34 !21 = !{i32 700000, i64 0, i32 0}
35 !22 = !{i32 800000, i64 0, i32 0}
36 !23 = !{i32 900000, i64 0, i32 0}
37 !24 = !{i32 950000, i64 0, i32 0}
38 !25 = !{i32 990000, i64 0, i32 0}
39 !26 = !{i32 999000, i64 0, i32 0}
40 !27 = !{i32 999900, i64 0, i32 0}
41 !28 = !{i32 999990, i64 0, i32 0}
42 !29 = !{i32 999999, i64 0, i32 0}
43 !33 = !{!"VP", i32 0, i64 100, i64 8400159624858369790, i64 100}