cmd/compile/internal/devirtualize: PGO devirtualization selects an edge with a weight of 0 as the hottest one #72092
Labels
BugReport
Issues describing a possible bug in the Go implementation.
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go version devel go1.25-4f45b2b7e0 Tue Mar 4 03:10:17 2025 -0800 linux/arm64
Output of
go env
in your module/workspace:What did you do?
Consider the following example (it is based on the function
(*Resolver).resolveAddrList
fromnet/dial.go
):Build and collect a profile:
What did you see happen?
As can be seen,
Unreachable
is never called. Hence, it hasn't appeared in the profile:However, the call
hint.Network()
in theUnreachable
function has been devirtualized:The reason is the following.
WeightedCG
contains all functions from a package being compiled. In our case (taken using-d=pgodebug=3
):There are nodes for both
(*UnixAddr).Network
and(*NotUnixAddr).Network
functions. The edgeUnreachable -> (*UnixAddr).Network
has a zero weight because there are no suitable samples in the profile.PGO devirtualization considers the call
hint.Network()
and tries to find the most appropriate candidate. For theUnreachable
node, it goes throughOutEdges
with the same callsite offset. Note that we can't distinguish callsitesaddr.Network()
andhint.Network()
because they are placed on the same line. The edge to(*UnixAddr).Network
is the only one because there are no samples related to theUnreachable
function. This callee'sAST != nil
, and the method receiver type implements the interfaceAddr
. So,hint.Network()
is devirtualized to(*UnixAddr).Network
, although this caller relates toaddr.Network()
and the weight of the edge is 0.I suppose we shouldn't devirtualize a call when a weight of its hottest edge is 0 even if its
AST != nil
. Moreover, the devirtualized call will be inlined later (as can be seen in the debug output shown above), and this leads to unjustified increase of code size.What did you expect to see?
The call
hint.Network()
shouldn't be devirtualized.The text was updated successfully, but these errors were encountered: