In many programs, event handling loop (not statically infinite) runs forever and the normal exit path is not executed unless there is error condition. Profile dumping can happen asynchronously. For such functions, if the entry block is not instrumented, we will get zero entry count which can be bad -- PGO relies on entry count to get BB count via scaling. See test case in D41058
This patch implements a new heuristic to select min edges -- if entry edges and exit edges have similar weight, prefer to select exit edges to be min edges.
This patch also fixes the problem with the real infinite loop case where entry count is zero.
Will this ever be true? EntryInWeight should be always greater than or equal to weight of Exit BB.