[SampleFDO] Fix invalid branch profile generated by indirect call promotion.
authorWei Mi <wmi@google.com>
Thu, 16 Jan 2020 02:23:36 +0000 (18:23 -0800)
committerWei Mi <wmi@google.com>
Thu, 16 Jan 2020 02:36:06 +0000 (18:36 -0800)
commit154cd6de513e1e9ce794ba2d1eae1647c873f812
tree943c1a4260ff7908e545ac38ac3c88e0461755ab
parente4454479212b28532909e0a0782b0102e9bcd1c4
[SampleFDO] Fix invalid branch profile generated by indirect call promotion.

Suppose an inline instance has hot total sample count but 0 entry count, and
it is an indirect call target. If the indirect call has no other call target
and inline instance associated with it and it is promoted, currently the
conditional branch generated by indirect call promotion will have invalid
branch profile which is !{!"branch_weights", i32 0, i32 0} -- because the
entry count of the promoted target is 0 and the total entry count of all
targets is also 0. This caused a SEGV in Control Height Reduction and may
cause problem in other passes.

Function entry count of an inline instance is computed by a heuristic --
using either the sample of the starting line or starting inner inline
instance. The patch changes the heuristic a little bit so that when total
sample count is larger than 0, the computed entry count will be at least 1.
Then the new branch profile will be !{!"branch_weights", i32 1, i32 0}.

Differential Revision: https://reviews.llvm.org/D72790
llvm/include/llvm/ProfileData/SampleProf.h
llvm/test/Transforms/SampleProfile/Inputs/indirect-call.compact.afdo
llvm/test/Transforms/SampleProfile/Inputs/indirect-call.prof
llvm/test/Transforms/SampleProfile/indirect-call.ll
llvm/test/Transforms/SampleProfile/inline-callee-update.ll