http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59724
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 31778 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31778&action=edit gcc49-pr59724.patch Ugh, what a mess. So, while ifcvt wants flow_find_head_matching_sequence to count only active insns, so that it matches it's counting, when try_head_merge_bb calls it, counting only active insns is problematic, because the count is used to find a minimum number of insns that match. Now, in the testcase we first try a pair of bbs where there is a match of 2 active insns and 1 non-active, then a pair where there is a match of only 2 active insns and no non-active. As 2 == 2, we take the first pair as shortest sequence, but we remember for that the last matching insn (which is the non-active one). The attached patch reverts the try_head_merge_bb and makes flow_find_head_matching_sequence behave differently between when called from try_head_merge_bb and ifcvt.