https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92924
--- Comment #17 from Jan Hubicka <hubicka at gcc dot gnu.org> --- I further hacked the script to record only values that are useful, where useful means with greater count then all / TOPN_VALUES / 2. I use same test in GCC itself (that was bug in original luxou's patch that it required count to be at least 50% so we did more then two speculations only when the number of targets was precisely 2 and probability precisely 50%). I also added special case for those calls which have only one target. Now I get: == Stats for all == stats for indirect_call: total: 160441 freq: 833372200 not executed at all: 134836 invalid: 0 (0.00%) freq:0 (0.00%) only one target: 20036 (12.49%) freq:108329394 (13.00%) tracked values: 0 values: 111 times (0.07%) freq: 14162014 (1.70%) 1 values: 2963 times (1.85%) freq: 594520090 (71.34%) 2 values: 2284 times (1.42%) freq: 111578254 (13.39%) 3 values: 185 times (0.12%) freq: 2525320 (0.30%) 4 values: 26 times (0.02%) freq: 2257128 (0.27%) stats for topn: total: 6620 freq: 16471134 not executed at all: 6236 invalid: 0 (0.00%) freq:0 (0.00%) only one target: 196 (2.96%) freq:3535103 (21.46%) tracked values: 0 values: 39 times (0.59%) freq: 5340350 (32.42%) 1 values: 84 times (1.27%) freq: 6006897 (36.47%) 2 values: 59 times (0.89%) freq: 1547519 (9.40%) 3 values: 6 times (0.09%) freq: 41265 (0.25%) 4 values: 0 times (0.00%) freq: 0 (0.00%) == Stats for mainline == stats for indirect_call: total: 160441 freq: 865715132 not executed at all: 134862 invalid: 156 (0.10%) freq:64839775 (7.49%) only one target: 1255 (0.78%) freq:604290 (0.07%) tracked values: 0 values: 14939 times (9.31%) freq: 356592480 (41.19%) 1 values: 8535 times (5.32%) freq: 377193150 (43.57%) 2 values: 660 times (0.41%) freq: 66082791 (7.63%) 3 values: 15 times (0.01%) freq: 133242 (0.02%) 4 values: 19 times (0.01%) freq: 269404 (0.03%) stats for topn: total: 6620 freq: 16793729 not executed at all: 6235 invalid: 10 (0.15%) freq:1307937 (7.79%) only one target: 10 (0.15%) freq:1300 (0.01%) tracked values: 0 values: 182 times (2.75%) freq: 9195915 (54.76%) 1 values: 156 times (2.36%) freq: 6111713 (36.39%) 2 values: 26 times (0.39%) freq: 173054 (1.03%) 3 values: 1 times (0.02%) freq: 3810 (0.02%) 4 values: 0 times (0.00%) freq: 0 (0.00%) So with 4 targets we seem to be able to track 98.3% of trained branhces while with reproducible merging this drops to 45% I will send you the hacked script